From 52bbfe926be03f66d57d15743e9914bc4e201c8c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:12:11 +0200 Subject: [PATCH] add uncrustify pre-commit hook --- bootstrap | 19 + contrib/auditor-report.tex.j2 | 9 +- contrib/uncrustify_precommit | 35 + src/auditor/auditor-basedb.fees | Bin 800 -> 0 bytes src/auditor/auditor-basedb.mpub | 2 +- src/auditor/auditor-basedb.sql | 4356 --------------------- src/auditor/generate-auditor-basedb.conf | 8 +- src/auditor/generate-auditor-basedb.sh | 8 +- src/auditor/taler-auditor.c | 143 +- src/auditor/taler-wire-auditor.c | 6 +- src/auditor/test-auditor.sh | 63 +- src/auditordb/plugin_auditordb_postgres.c | 17 +- src/auditordb/test_auditordb.c | 17 +- src/include/taler_auditordb_plugin.h | 8 +- 14 files changed, 280 insertions(+), 4411 deletions(-) create mode 100755 contrib/uncrustify_precommit delete mode 100644 src/auditor/auditor-basedb.fees delete mode 100644 src/auditor/auditor-basedb.sql diff --git a/bootstrap b/bootstrap index 1ad18f7bf..0d35d01ce 100755 --- a/bootstrap +++ b/bootstrap @@ -1,3 +1,22 @@ #!/bin/sh git submodule update --init + +# This is more portable than `which' but comes with +# the caveat of not(?) properly working on busybox's ash: +existence() +{ + command -v "$1" >/dev/null 2>&1 +} + + +if existence uncrustify; then + echo "Installing uncrustify hook and configuration" + # Install uncrustify format symlink (if possible) + ln -s contrib/uncrustify.cfg uncrustify.cfg 2> /dev/null + # Install pre-commit hook (if possible) + ln -s ../../contrib/uncrustify_precommit .git/hooks/pre-commit 2> /dev/null +else + echo "Uncrustify not detected, hook not installed. Please install uncrustify if you plan on doing development" +fi + autoreconf -fi diff --git a/contrib/auditor-report.tex.j2 b/contrib/auditor-report.tex.j2 index 33aab79cf..7694ccea8 100644 --- a/contrib/auditor-report.tex.j2 +++ b/contrib/auditor-report.tex.j2 @@ -93,7 +93,7 @@ This section analyzes the income of the exchange operator from fees. Deposit fees & {{ data.total_deposit_fee_income }} \\ Melt fees & {{ data.total_melt_fee_income }} \\ Refund fees & {{ data.total_refund_fee_income }} \\ - Aggregation fees & {{ data.total_aggregation_fee_income }} \\ + Aggregation fees & {{ data.total_aggregation_fee_income }} \\ \hline \hline {\bf Total} & {{ data.income_fee_total }} \\ \end{tabular} \end{center} @@ -845,7 +845,7 @@ impact. {% if data.row_inconsistencies|length() == 0 %} {\bf No row inconsistencies found.} {% else %} - \begin{longtable}{p{2.5cm}|l|p{7cm}} + \begin{longtable}{p{2.5cm}|l|p{5cm}} {\bf Table} & {\bf Row} & {\bf Diagnostic} \\ \hline \hline \endfirsthead @@ -881,11 +881,12 @@ This section describes cases where the exchange did not close a reserve and wire back the remaining funds when the reserve expired. +% Table generation tested by testcase #21 in test-auditor.sh {% if data.reserve_not_closed_inconsistencies|length() == 0 %} {\bf All expired reserves were closed.} {% else %} - \begin{longtable}{p{5.5cm}|c|r} + \begin{longtable}{p{4.5cm}|c|r} {\bf Reserve} & {\bf Expired} & {\bf Balance} \\ \hline \hline \endfirsthead {\bf Reserve} & {\bf Expired} & {\bf Balance} \\ \hline \hline @@ -900,7 +901,7 @@ reserve expired. \label{table:reserve:not_closed} \endlastfoot {% for item in data.reserve_not_closed_inconsistencies %} - {\tt \tiny {{ item.reserve_pub }} } & + {\tt \tiny \truncate{4.3cm}{ {{ item.reserve_pub }} } } & {\tiny {{ item.expiration_time }} } & {{ item.balance }} \\ \hline {% endfor %} diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit new file mode 100755 index 000000000..fd29998c3 --- /dev/null +++ b/contrib/uncrustify_precommit @@ -0,0 +1,35 @@ +#!/bin/sh + +# use as .git/hooks/pre-commit + +exec 1>&2 + +RET=0 +changed=$(git diff --cached --name-only) +crustified="" + +for f in $changed; +do + if echo $f | grep \\.[c,h]\$ > /dev/null + then + # compare result of uncrustify with changes + # + # only change any of the invocations here if + # they are portable across all cmp and shell + # implementations ! + uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f - + if test $? = 1 ; + then + crustified=" $crustified $f" + RET=1 + fi + fi +done + +if [ $RET = 1 ]; +then + echo "Run" + echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}" + echo "before commiting." +fi +exit $RET diff --git a/src/auditor/auditor-basedb.fees b/src/auditor/auditor-basedb.fees deleted file mode 100644 index 6cbdd1c6981b392f5245c261739793aa0bbaf939..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 800 zcmZQzVCZ0AU}5>mIVF8>hhJN}Xyh`jdgW~|%Jy@38JJ5<+$uEZi3_jIKK1pF+b_@7 zd2ur-YOh7B_zCGhy(>RG_;J!*`hV&QrcDg2b&>Hwdl(p4XS2Ufo5KJH{7w!buE8PR zp)UTxa6upgO`PfN%%I&dAA=X~+IL}kKxA1LOSN`~-J$TSH_YYp0)n9<^-BZC4WHO&$|88)WACk7o)isE`cV_dSy+A zZbr*7n#r3#d0q%Tb4+nTS@Fx0v!}+&S2d`nHC^$Tvn%D#!GZ;EJI)(_ z%PW0fjVJ`v8cCQJI$_epHg3)ssiKB()o`Y&ubJL^Jk=#=le%hs?0&81R& zK;6&!QGIPC>FJ8$0;llqcZ(L4oPXf{=w|lQF4utd?_{+b6(in-gtcEN__=%cX*m;N fu767|^r!vb|LV>~;TG`~X63q taler-exchange-wire.log -taler-exchange-keyup -c $CONF -o e2a.dat 2> taler-exchange-keyup.log +taler-exchange-keyup -L INFO -c $CONF -o e2a.dat 2> taler-exchange-keyup.log # setup auditor echo "Setting up auditor" -taler-auditor-dbinit -c $CONF -taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL +taler-auditor-dbinit -r -c $CONF +taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL taler-auditor-sign -c $CONF -u $AUDITOR_URL -r e2a.dat -o a2e.dat -m $MASTER_PUB # Launch services diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index 6ab9bb344..87fa621bc 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -838,6 +838,11 @@ struct ReserveSummary */ struct GNUNET_TIME_Absolute a_expiration_date; + /** + * Which account did originally put money into the reserve? + */ + char *sender_account; + /** * Did we have a previous reserve info? Used to decide between * UPDATE and INSERT later. Initialized in @@ -870,7 +875,8 @@ load_auditor_reserve_summary (struct ReserveSummary *rs) &rowid, &rs->a_balance, &rs->a_withdraw_fee_balance, - &rs->a_expiration_date); + &rs->a_expiration_date, + &rs->sender_account); if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); @@ -977,6 +983,7 @@ handle_reserve_in (void *cls, if (NULL == rs) { rs = GNUNET_new (struct ReserveSummary); + rs->sender_account = GNUNET_strdup (sender_account_details); rs->reserve_pub = *reserve_pub; rs->total_in = *credit; GNUNET_assert (GNUNET_OK == @@ -1362,6 +1369,52 @@ handle_payback_by_reserve (void *cls, } +/** + * Obtain the closing fee for a transfer at @a time for target + * @a receiver_account. + * + * @param receiver_account payto:// URI of the target account + * @param atime when was the transfer made + * @param fee[out] set to the closing fee + * @return #GNUNET_OK on success + */ +static int +get_closing_fee (const char *receiver_account, + struct GNUNET_TIME_Absolute atime, + struct TALER_Amount *fee) +{ + struct TALER_MasterSignatureP master_sig; + struct GNUNET_TIME_Absolute start_date; + struct GNUNET_TIME_Absolute end_date; + struct TALER_Amount wire_fee; + char *method; + + method = TALER_WIRE_payto_get_method (receiver_account); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Method is `%s'\n", + method); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + edb->get_wire_fee (edb->cls, + esession, + method, + atime, + &start_date, + &end_date, + &wire_fee, + fee, + &master_sig)) + { + report_row_inconsistency ("closing-fee", + atime.abs_value_us, + "closing fee unavailable at given time"); + GNUNET_free (method); + return GNUNET_SYSERR; + } + GNUNET_free (method); + return GNUNET_OK; +} + + /** * Function called about reserve closing operations * the aggregator triggered. @@ -1426,6 +1479,8 @@ handle_reserve_closed (void *cls, } else { + struct TALER_Amount expected_fee; + GNUNET_assert (GNUNET_OK == TALER_amount_add (&rs->total_out, &rs->total_out, @@ -1434,6 +1489,30 @@ handle_reserve_closed (void *cls, TALER_amount_add (&rs->total_fee, &rs->total_fee, closing_fee)); + /* verify closing_fee is correct! */ + if (GNUNET_OK != + get_closing_fee (receiver_account, + execution_date, + &expected_fee)) + { + GNUNET_break (0); + } + else if (0 != TALER_amount_cmp (&expected_fee, + closing_fee)) + { + report_amount_arithmetic_inconsistency ("closing aggregation fee", + rowid, + closing_fee, + &expected_fee, + 1); + } + } + 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", @@ -1464,6 +1543,7 @@ verify_reserve_balance (void *cls, struct TALER_EXCHANGEDB_Reserve reserve; struct TALER_Amount balance; struct TALER_Amount nbalance; + struct TALER_Amount cfee; enum GNUNET_DB_QueryStatus qs; int ret; @@ -1566,25 +1646,46 @@ verify_reserve_balance (void *cls, } /* Check that reserve is being closed if it is past its expiration date */ - /* FIXME: need to consider closing_fee here! */ - if ( (CLOSING_GRACE_PERIOD.rel_value_us > - GNUNET_TIME_absolute_get_duration ( - rs->a_expiration_date).rel_value_us) && - ( (0 != nbalance.value) || - (0 != nbalance.fraction) ) ) + + if (CLOSING_GRACE_PERIOD.rel_value_us < + GNUNET_TIME_absolute_get_duration (rs->a_expiration_date).rel_value_us) { - GNUNET_assert (GNUNET_OK == - TALER_amount_add (&total_balance_reserve_not_closed, - &total_balance_reserve_not_closed, - &nbalance)); - report (report_reserve_not_closed_inconsistencies, - json_pack ("{s:o, s:o, s:o}", - "reserve_pub", - GNUNET_JSON_from_data_auto (&rs->reserve_pub), - "balance", - TALER_JSON_from_amount (&nbalance), - "expiration_time", - json_from_time_abs (rs->a_expiration_date))); + if ( (NULL != rs->sender_account) && + (GNUNET_OK == + get_closing_fee (rs->sender_account, + rs->a_expiration_date, + &cfee)) ) + { + if (1 == TALER_amount_cmp (&nbalance, + &cfee)) + { + GNUNET_assert (GNUNET_OK == + TALER_amount_add (&total_balance_reserve_not_closed, + &total_balance_reserve_not_closed, + &nbalance)); + report (report_reserve_not_closed_inconsistencies, + json_pack ("{s:o, s:o, s:o}", + "reserve_pub", + GNUNET_JSON_from_data_auto (&rs->reserve_pub), + "balance", + TALER_JSON_from_amount (&nbalance), + "expiration_time", + json_from_time_abs (rs->a_expiration_date))); + } + } + else + { + report (report_reserve_not_closed_inconsistencies, + json_pack ("{s:o, s:o, s:o, s:s}", + "reserve_pub", + GNUNET_JSON_from_data_auto (&rs->reserve_pub), + "balance", + TALER_JSON_from_amount (&nbalance), + "expiration_time", + json_from_time_abs (rs->a_expiration_date), + "diagnostic", + "could not determine closing fee")); + } } /* Add withdraw fees we encountered to totals */ @@ -1672,7 +1773,8 @@ verify_reserve_balance (void *cls, &master_pub, &nbalance, &rs->a_withdraw_fee_balance, - rs->a_expiration_date); + rs->a_expiration_date, + rs->sender_account); if (0 >= qs) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); @@ -1684,6 +1786,7 @@ cleanup: GNUNET_CONTAINER_multihashmap_remove (rc->reserves, key, rs)); + GNUNET_free_non_null (rs->sender_account); GNUNET_free (rs); return ret; } diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c index fe6b66015..4d624e1ef 100644 --- a/src/auditor/taler-wire-auditor.c +++ b/src/auditor/taler-wire-auditor.c @@ -695,9 +695,6 @@ wire_missing_cb (void *cls, /** * Checks that all wire transfers that should have happened * (based on deposits) have indeed happened. - * - * FIXME: this check _might_ rather belong with the - * taler-auditor logic. */ static void check_for_required_transfers () @@ -712,7 +709,8 @@ check_for_required_transfers () next_timestamp = GNUNET_TIME_absolute_subtract (next_timestamp, GRACE_PERIOD); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Analyzing exchange's unfinished deposits\n"); + "Analyzing exchange's unfinished deposits (deadline: %s)\n", + GNUNET_STRINGS_absolute_time_to_string (next_timestamp)); qs = edb->select_deposits_missing_wire (edb->cls, esession, pp.last_timestamp, diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index bac536ea1..aa8bcb0f1 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -68,15 +68,15 @@ function pre_audit () { function audit_only () { # Run the auditor! echo -n "Running audit(s) ..." - taler-auditor -r -c $CONF -m $MASTER_PUB > test-audit.json 2> test-audit.log || exit_fail "auditor failed" + taler-auditor -L INFO -r -c $CONF -m $MASTER_PUB > test-audit.json 2> test-audit.log || exit_fail "auditor failed" echo -n "." # Also do incremental run - taler-auditor -c $CONF -m $MASTER_PUB > test-audit-inc.json 2> test-audit-inc.log || exit_fail "auditor failed" + taler-auditor -L INFO -c $CONF -m $MASTER_PUB > test-audit-inc.json 2> test-audit-inc.log || exit_fail "auditor failed" echo -n "." - taler-wire-auditor -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" + taler-wire-auditor -L INFO -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" # Also do incremental run echo -n "." - taler-wire-auditor -c $CONF -m $MASTER_PUB > test-wire-audit-inc.json 2> test-wire-audit-inc.log || exit_fail "wire auditor failed" + taler-wire-auditor -L INFO -c $CONF -m $MASTER_PUB > test-wire-audit-inc.json 2> test-wire-audit-inc.log || exit_fail "wire auditor failed" echo " DONE" } @@ -382,6 +382,10 @@ echo "UPDATE deposits SET wire='{\"url\":\"payto://x-taler-bank/localhost:8082/4 run_audit +echo -n "Testing inconsistency detection... " + +jq -e .bad_sig_losses[0] < test-audit.json > /dev/null || exit_fail "Bad signature not detected" + ROW=`jq -e .bad_sig_losses[0].row < test-audit.json` if test $ROW != 1 then @@ -406,6 +410,7 @@ then exit_fail "Wrong total bad sig loss, got $LOSS" fi +echo PASS # Undo: echo "UPDATE deposits SET wire='$OLD_WIRE' WHERE deposit_serial_id=1" | psql -Aqt $DB @@ -1076,16 +1081,62 @@ echo "UPDATE app_banktransaction SET subject='${OLD_SUBJECT}' WHERE debit_accoun } +# Test where reserve closure was done properly +function test_20() { +echo "===========20: 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` +NEW_TIME=`expr $OLD_TIME - 3024000000000` # 5 weeks +NEW_CREDIT=`expr $OLD_VAL + 100` +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 + +# Need to run with the aggregator so the reserve closure happens +run_audit aggregator + +echo -n "Testing reserve closure was done correctly... " + +jq -e .reserve_not_closed_inconsistencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected reserve not closed inconsistency detected" + +echo "PASS" + +# Undo +echo "UPDATE reserves_in SET execution_date='${OLD_TIME}',credit_val=${OLD_VAL} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB +} + + +# Test where reserve closure was not done properly +function test_21() { +echo "===========21: 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` # 5 weeks +NEW_CREDIT=`expr $OLD_VAL + 100` +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 -n "Testing reserve closure missing detected... " +jq -e .reserve_not_closed_inconsistencies[0] < test-audit.json > /dev/null || exit_fail "Reserve not closed inconsistency not detected" +echo "PASS" + +# Undo +echo "UPDATE reserves_in SET execution_date='${OLD_TIME}',credit_val=${OLD_VAL} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB +} # ************************************************** # FIXME: Add more tests here! :-) # Specifically: -# - emergencies (detection) +# - reserve closure (or lack thereof) # - revocation (payback, accepting # of coins despite denomination revocation) # - refunds -# - reserve closure (or lack thereof) # - arithmetic problems # ************************************************** diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 9450ae94f..287bef28a 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -329,6 +329,7 @@ postgres_create_tables (void *cls) ",withdraw_fee_balance_frac INT4 NOT NULL" ",expiration_date INT8 NOT NULL" ",auditor_reserves_rowid BIGSERIAL UNIQUE" + ",origin_account TEXT" ")"), GNUNET_PQ_make_try_execute ("CREATE INDEX auditor_reserves_by_reserve_pub " "ON auditor_reserves(reserve_pub)"), @@ -777,8 +778,9 @@ postgres_prepare (PGconn *db_conn) ",withdraw_fee_balance_val" ",withdraw_fee_balance_frac" ",expiration_date" - ") VALUES ($1,$2,$3,$4,$5,$6,$7);", - 7), + ",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" @@ -798,6 +800,7 @@ postgres_prepare (PGconn *db_conn) ",withdraw_fee_balance_frac" ",expiration_date" ",auditor_reserves_rowid" + ",origin_account" " FROM auditor_reserves" " WHERE reserve_pub=$1 AND master_pub=$2;", 2), @@ -2475,6 +2478,7 @@ postgres_get_wire_auditor_progress (void *cls, * @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 @@ -2484,7 +2488,8 @@ postgres_insert_reserve_info (void *cls, const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_Amount *reserve_balance, const struct TALER_Amount *withdraw_fee_balance, - struct GNUNET_TIME_Absolute expiration_date) + struct GNUNET_TIME_Absolute expiration_date, + const char *origin_account) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (reserve_pub), @@ -2492,6 +2497,7 @@ postgres_insert_reserve_info (void *cls, TALER_PQ_query_param_amount (reserve_balance), TALER_PQ_query_param_amount (withdraw_fee_balance), TALER_PQ_query_param_absolute_time (&expiration_date), + GNUNET_PQ_query_param_string (origin_account), GNUNET_PQ_query_param_end }; @@ -2586,6 +2592,7 @@ postgres_del_reserve_info (void *cls, * @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 @@ -2596,7 +2603,8 @@ postgres_get_reserve_info (void *cls, uint64_t *rowid, struct TALER_Amount *reserve_balance, struct TALER_Amount *withdraw_fee_balance, - struct GNUNET_TIME_Absolute *expiration_date) + struct GNUNET_TIME_Absolute *expiration_date, + char **sender_account) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -2609,6 +2617,7 @@ postgres_get_reserve_info (void *cls, TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance", withdraw_fee_balance), TALER_PQ_result_spec_absolute_time ("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 }; diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c index 8f1b7da8a..3968f0218 100644 --- a/src/auditordb/test_auditordb.c +++ b/src/auditordb/test_auditordb.c @@ -291,6 +291,7 @@ run (void *cls) TALER_string_to_amount (CURRENCY ":23.456789", &withdraw_fee_balance)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_reserve_info (plugin->cls, session, @@ -298,7 +299,8 @@ run (void *cls) &master_pub, &reserve_balance, &withdraw_fee_balance, - past)); + past, + "payto://bla/blub")); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: update_reserve_info\n"); @@ -315,6 +317,8 @@ run (void *cls) 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, session, @@ -323,8 +327,11 @@ run (void *cls) &rowid, &reserve_balance2, &withdraw_fee_balance2, - &date)); - + &date, + &payto)); + FAILIF (0 != strcmp (payto, + "payto://bla/blub")); + GNUNET_free (payto); FAILIF (0 != GNUNET_memcmp (&date, &future) || 0 != GNUNET_memcmp (&reserve_balance2, &reserve_balance) || 0 != GNUNET_memcmp (&withdraw_fee_balance2, @@ -725,7 +732,7 @@ run (void *cls) result = 0; - drop: +drop: if (NULL != session) { plugin->rollback (plugin->cls, @@ -746,7 +753,7 @@ run (void *cls) GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls, GNUNET_YES)); - unload: +unload: TALER_AUDITORDB_plugin_unload (plugin); plugin = NULL; } diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h index bb59bf9c3..52cd016da 100644 --- a/src/include/taler_auditordb_plugin.h +++ b/src/include/taler_auditordb_plugin.h @@ -1007,6 +1007,7 @@ struct TALER_AUDITORDB_Plugin * @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 */ enum GNUNET_DB_QueryStatus @@ -1016,7 +1017,8 @@ struct TALER_AUDITORDB_Plugin const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_Amount *reserve_balance, const struct TALER_Amount *withdraw_fee_balance, - struct GNUNET_TIME_Absolute expiration_date); + struct GNUNET_TIME_Absolute expiration_date, + const char *origin_account); /** @@ -1055,6 +1057,7 @@ struct TALER_AUDITORDB_Plugin * @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 */ enum GNUNET_DB_QueryStatus @@ -1065,7 +1068,8 @@ struct TALER_AUDITORDB_Plugin uint64_t *rowid, struct TALER_Amount *reserve_balance, struct TALER_Amount *withdraw_fee_balance, - struct GNUNET_TIME_Absolute *expiration_date); + struct GNUNET_TIME_Absolute *expiration_date, + char **sender_account); /**