gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] branch master updated (cddce0f -> 82cec70)


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (cddce0f -> 82cec70)
Date: Tue, 16 May 2017 11:05:11 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository exchange.

    from cddce0f  minor edits to the paper, moving refresh around, etc.
     new d3fac18  take the history array from "data" field returned by the bank
     new be3b891  fix port numbers, no longer 8081 but on 8080; and box json 
array /history response in {data} as required by API
     new 7c28823  handle base32-wire transfer subject being followed by 
space+exchange base url in wire plugin and fakebank
     new bdfa188  start_row is actually start in the spec, fix naming
     new 9916eef  use and purge alternate db when testing against python bank
     new 82cec70  nicer error reporting

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/bank-lib/Makefile.am                   |  5 +---
 src/bank-lib/bank_api_history.c            | 16 +++++++++---
 src/bank-lib/fakebank.c                    | 28 +++++++++++++++++----
 src/bank-lib/test_bank_api.c               | 15 ++++++++---
 src/bank-lib/test_bank_api_with_fakebank.c |  6 ++---
 src/bank-lib/test_bank_interpreter.c       | 40 +++++++++++++++++++++++-------
 src/include/taler_bank_service.h           |  3 ++-
 src/wire/plugin_wire_test.c                | 18 ++++++++++++--
 8 files changed, 99 insertions(+), 32 deletions(-)

diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 72c25f6..48c7e9c 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -57,10 +57,7 @@ check_PROGRAMS = \
   test_bank_api_with_fakebank
 
 TESTS = \
-  test_bank_api
-#  test_bank_api_with_fakebank
-# For now, test_bank_api is known NOT to work (#5005, #4964, etc.)
-# $(check_PROGRAMS)
+  $(check_PROGRAMS)
 
 test_bank_api_SOURCES = \
   test_bank_interpreter.c test_bank_interpreter.h \
diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c
index ecb3561..e134f20 100644
--- a/src/bank-lib/bank_api_history.c
+++ b/src/bank-lib/bank_api_history.c
@@ -77,7 +77,14 @@ static int
 parse_account_history (struct TALER_BANK_HistoryHandle *hh,
                        const json_t *history)
 {
-  for (unsigned int i=0;i<json_array_size (history);i++)
+  json_t *history_array;
+
+  if (NULL == (history_array = json_object_get (history, "data")))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  for (unsigned int i=0;i<json_array_size (history_array);i++)
   {
     struct TALER_BANK_TransferDetails td;
     const char *sign;
@@ -99,7 +106,7 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh,
                                &other_account),
       GNUNET_JSON_spec_end()
     };
-    json_t *transaction = json_array_get (history,
+    json_t *transaction = json_array_get (history_array,
                                           i);
 
     if (GNUNET_OK !=
@@ -110,6 +117,7 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh,
       GNUNET_break_op (0);
       return GNUNET_SYSERR;
     }
+
     td.account_details = json_pack ("{s:s, s:s, s:I}",
                                     "type", "test",
                                     "bank_uri", hh->bank_base_url,
@@ -265,13 +273,13 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
   {
     if (TALER_BANK_DIRECTION_BOTH == direction)
       GNUNET_asprintf (&url,
-                       
"/history?auth=basic&account_number=%llu&delta=%lld&start_row=%llu",
+                       
"/history?auth=basic&account_number=%llu&delta=%lld&start=%llu",
                        (unsigned long long) account_number,
                        (long long) num_results,
                        (unsigned long long) start_row);
     else
       GNUNET_asprintf (&url,
-                       
"/history?auth=basic&account_number=%llu&delta=%lld&start_row=%llu&direction=%s",
+                       
"/history?auth=basic&account_number=%llu&delta=%lld&start=%llu&direction=%s",
                        (unsigned long long) account_number,
                        (long long) num_results,
                        (unsigned long long) start_row,
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 0359b4a..813d5b2 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -411,6 +411,7 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
   enum TALER_BANK_Direction direction;
   struct Transaction *pos;
   json_t *history;
+  json_t *jresponse;
   int ret;
 
   auth = MHD_lookup_connection_value (connection,
@@ -424,7 +425,7 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
                                      "direction");
   start = MHD_lookup_connection_value (connection,
                                        MHD_GET_ARGUMENT_KIND,
-                                       "start_row");
+                                       "start");
   acc = MHD_lookup_connection_value (connection,
                                      MHD_GET_ARGUMENT_KIND,
                                      "account_number");
@@ -511,8 +512,17 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
       continue;
     }
 
-    subject = GNUNET_STRINGS_data_to_string_alloc (&pos->wtid,
-                                                   sizeof (pos->wtid));
+    {
+      char *ws;
+
+      ws = GNUNET_STRINGS_data_to_string_alloc (&pos->wtid,
+                                                sizeof (pos->wtid));
+      GNUNET_asprintf (&subject,
+                       "%s %s",
+                       ws,
+                       pos->exchange_base_url);
+      GNUNET_free (ws);
+    }
     trans = json_pack ("{s:I, s:o, s:o, s:s, s:I, s:s}",
                        "row_id", (json_int_t) pos->serial_id,
                        "date", GNUNET_JSON_from_time_abs (pos->date),
@@ -536,7 +546,6 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
       count++;
     }
   }
-
   if (0 == json_array_size (history))
   {
     struct MHD_Response *resp;
@@ -552,14 +561,23 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
     return ret;
   }
 
+  jresponse = json_pack ("{s:o}",
+                         "data", history);
+  if (NULL == jresponse)
+  {
+    GNUNET_break (0);
+    return MHD_NO;
+  }
+
   /* Finally build response object */
   {
     struct MHD_Response *resp;
     void *json_str;
     size_t json_len;
 
-    json_str = json_dumps (history,
+    json_str = json_dumps (jresponse,
                            JSON_INDENT(2));
+    json_decref (jresponse);
     if (NULL == json_str)
     {
       GNUNET_break (0);
diff --git a/src/bank-lib/test_bank_api.c b/src/bank-lib/test_bank_api.c
index 4a37852..850b25f 100644
--- a/src/bank-lib/test_bank_api.c
+++ b/src/bank-lib/test_bank_api.c
@@ -53,7 +53,7 @@ run (void *cls)
       .details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
       .details.admin_add_incoming.credit_account_no = 1,
       .details.admin_add_incoming.debit_account_no = 2, /* Ignored */
-      .details.admin_add_incoming.amount = "PUDOS:5.01" },
+      .details.admin_add_incoming.amount = "KUDOS:5.01" },
     /* Move money from Exchange to Bank */
     { .oc = TBI_OC_ADMIN_ADD_INCOMING,
       .label = "deposit-2",
@@ -61,7 +61,7 @@ run (void *cls)
       .details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
       .details.admin_add_incoming.credit_account_no = 1,
       .details.admin_add_incoming.debit_account_no = 2, /* Ignored */
-      .details.admin_add_incoming.amount = "PUDOS:5.01" },
+      .details.admin_add_incoming.amount = "KUDOS:5.01" },
     /* Ask Exchange's incoming history */
     { .oc = TBI_OC_HISTORY,
       .label = "history-1c",
@@ -76,7 +76,6 @@ run (void *cls)
       .details.history.direction = TALER_BANK_DIRECTION_DEBIT,
       .details.history.start_row_ref = NULL,
       .details.history.num_results = 5 },
-    # if 0
     /* Ask Exchange's outgoing history, last 5 records */
     { .oc = TBI_OC_HISTORY,
       .label = "history-2dr",
@@ -90,7 +89,6 @@ run (void *cls)
       .details.history.direction = TALER_BANK_DIRECTION_DEBIT,
       .details.history.start_row_ref = "deposit-1",
       .details.history.num_results = 5 },
-  #endif
     { .oc = TBI_OC_END }
   };
 
@@ -126,11 +124,20 @@ main (int argc,
   GNUNET_log_setup ("test-bank-api",
                     "WARNING",
                     NULL);
+
+  if (0 != system ("taler-bank-manage --with-db=postgres:///talercheck django 
flush --no-input"))
+  {
+      fprintf (stderr,
+               "Could not purge database 'talercheck'\n");
+      return 77;
+  }
+
   bankd = GNUNET_OS_start_process (GNUNET_NO,
                                    GNUNET_OS_INHERIT_STD_ALL,
                                    NULL, NULL, NULL,
                                    "taler-bank-manage",
                                    "taler-bank-manage",
+                                   "--with-db", "postgres:///talercheck",
                                    "serve-http",
                                    "--port", "8080",
                                    NULL);
diff --git a/src/bank-lib/test_bank_api_with_fakebank.c 
b/src/bank-lib/test_bank_api_with_fakebank.c
index 01ab30c..e16c3a9 100644
--- a/src/bank-lib/test_bank_api_with_fakebank.c
+++ b/src/bank-lib/test_bank_api_with_fakebank.c
@@ -52,7 +52,7 @@ run (void *cls)
       .details.admin_add_incoming.credit_account_no = 1,
       .details.admin_add_incoming.debit_account_no = 2,
       .details.admin_add_incoming.exchange_base_url = "https://exchange.net/";,
-      .details.admin_add_incoming.amount = "PUDOS:5.01" },
+      .details.admin_add_incoming.amount = "KUDOS:5.01" },
     /* Add EUR:3.21 to account 3 */
     { .oc = TBI_OC_HISTORY,
       .label = "history-1c",
@@ -72,14 +72,14 @@ run (void *cls)
       .details.admin_add_incoming.credit_account_no = 3,
       .details.admin_add_incoming.debit_account_no = 2,
       .details.admin_add_incoming.exchange_base_url = "https://exchange.org/";,
-      .details.admin_add_incoming.amount = "PUDOS:3.21" },
+      .details.admin_add_incoming.amount = "KUDOS:3.21" },
     { .oc = TBI_OC_ADMIN_ADD_INCOMING,
       .label = "credit-2",
       .details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
       .details.admin_add_incoming.credit_account_no = 2,
       .details.admin_add_incoming.debit_account_no = 3,
       .details.admin_add_incoming.exchange_base_url = "https://exchange.org/";,
-      .details.admin_add_incoming.amount = "PUDOS:3.22" },
+      .details.admin_add_incoming.amount = "KUDOS:3.22" },
     { .oc = TBI_OC_HISTORY,
       .label = "history-2b",
       .details.history.account_number = 2,
diff --git a/src/bank-lib/test_bank_interpreter.c 
b/src/bank-lib/test_bank_interpreter.c
index c53d53a..e966424 100644
--- a/src/bank-lib/test_bank_interpreter.c
+++ b/src/bank-lib/test_bank_interpreter.c
@@ -290,7 +290,7 @@ build_history (struct InterpreterState *is,
                      "type",
                      "test",
                      "bank_uri",
-                     "http://localhost:8081";,
+                     "http://localhost:8080";,
                      "account_number",
                      (json_int_t) 
pos->details.admin_add_incoming.debit_account_no);
       GNUNET_assert (NULL != h[total].details.account_details);
@@ -305,7 +305,7 @@ build_history (struct InterpreterState *is,
                      "type",
                      "test",
                      "bank_uri",
-                     "http://localhost:8081";,
+                     "http://localhost:8080";,
                      "account_number",
                      (json_int_t) 
pos->details.admin_add_incoming.credit_account_no);
       GNUNET_assert (NULL != h[total].details.account_details);
@@ -323,9 +323,17 @@ build_history (struct InterpreterState *is,
       /* h[total].execution_date; // unknown here */
       h[total].serial_id
         = pos->details.admin_add_incoming.serial_id;
-      h[total].details.wire_transfer_subject
-        = GNUNET_STRINGS_data_to_string_alloc 
(&pos->details.admin_add_incoming.wtid,
-                                               sizeof (struct 
TALER_WireTransferIdentifierRawP));
+      {
+        char *ws;
+
+        ws = GNUNET_STRINGS_data_to_string_alloc 
(&pos->details.admin_add_incoming.wtid,
+                                                  sizeof (struct 
TALER_WireTransferIdentifierRawP));
+        GNUNET_asprintf (&h[total].details.wire_transfer_subject,
+                         "%s %s",
+                         ws,
+                         pos->details.admin_add_incoming.exchange_base_url);
+        GNUNET_free (ws);
+      }
       total++;
     }
   }
@@ -366,7 +374,8 @@ print_expected (struct History *h,
                 (unsigned long long) h[i].serial_id,
                 h[i].details.wire_transfer_subject,
                 acc);
-    GNUNET_free_non_null (acc);
+    if (NULL != acc)
+      free (acc);
   }
 }
 
@@ -555,8 +564,8 @@ history_cb (void *cls,
     {
       uint64_t total;
       struct History *h;
-      GNUNET_break (0);
 
+      GNUNET_break (0);
       total = build_history (is,
                              &h);
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -571,7 +580,7 @@ history_cb (void *cls,
     }
     is->ip++;
     is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
-                                       is);
+                                         is);
     return;
   }
   if (GNUNET_OK !=
@@ -581,6 +590,19 @@ history_cb (void *cls,
                     details))
   {
     GNUNET_break (0);
+    {
+      char *acc;
+
+      acc = json_dumps (json,
+                        JSON_COMPACT);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Result %u was `%s'\n",
+                  (unsigned int) cmd->details.history.results_obtained,
+                  acc);
+      if (NULL != acc)
+        free (acc);
+    }
+
     cmd->details.history.failed = GNUNET_YES;
     return;
   }
@@ -853,7 +875,7 @@ TBI_run_interpreter (int *resultp,
 
   is = GNUNET_new (struct InterpreterState);
   if (GNUNET_YES == run_bank)
-    is->fakebank = TALER_FAKEBANK_start (8081);
+    is->fakebank = TALER_FAKEBANK_start (8080);
   is->resultp = resultp;
   is->commands = commands;
   is->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h
index 803250d..246174d 100644
--- a/src/include/taler_bank_service.h
+++ b/src/include/taler_bank_service.h
@@ -200,7 +200,8 @@ struct TALER_BANK_TransferDetails
   struct GNUNET_TIME_Absolute execution_date;
 
   /**
-   * Wire transfer subject
+   * Wire transfer subject.  Usually a reserve public key
+   * followed by the BASE URI of the exchange.
    */
   char *wire_transfer_subject;
 
diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c
index de3a6ab..8d625ce 100644
--- a/src/wire/plugin_wire_test.c
+++ b/src/wire/plugin_wire_test.c
@@ -822,16 +822,29 @@ bhist_cb (void *cls,
 
   if (MHD_HTTP_OK == http_status)
   {
+    char *subject;
+    char *space;
+
     wd.amount = details->amount;
     wd.execution_date = details->execution_date;
+    subject = GNUNET_strdup (details->wire_transfer_subject);
+    space = strchr (subject, (int) ' ');
+    if (NULL != space)
+    {
+      /* Space separates the actual wire transfer subject from the
+         exchange base URL (if present, expected only for outgoing
+         transactions).  So we cut the string off at the space. */
+      *space = '\0';
+    }
     /* NOTE: For a real bank, the subject should include a checksum! */
     if (GNUNET_OK !=
-        GNUNET_STRINGS_string_to_data (details->wire_transfer_subject,
-                                       strlen (details->wire_transfer_subject),
+        GNUNET_STRINGS_string_to_data (subject,
+                                       strlen (subject),
                                        &wd.reserve_pub,
                                        sizeof (wd.reserve_pub)))
     {
       GNUNET_break (0);
+      GNUNET_free (subject);
       /* NOTE: for a "real" bank, we would want to trigger logic to undo the
          wire transfer. However, for the "demo" bank, it should currently
          be "impossible" to do wire transfers with invalid subjects, and
@@ -839,6 +852,7 @@ bhist_cb (void *cls,
          that nicely either right now). So we don't handle this case for now. 
*/
       return;
     }
+    GNUNET_free (subject);
     wd.account_details = details->account_details;
 
     if ( (NULL != whh->hres_cb) &&

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]