gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -enable signup bonus with fakeba


From: gnunet
Subject: [taler-exchange] branch master updated: -enable signup bonus with fakebank
Date: Thu, 25 Aug 2022 19:52:56 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new ecae3c26 -enable signup bonus with fakebank
ecae3c26 is described below

commit ecae3c26dd054f8c17e335622036a1e38a48ed9a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Aug 25 19:52:53 2022 +0200

    -enable signup bonus with fakebank
---
 src/bank-lib/fakebank.c           | 24 ++++++++++++++++++++++--
 src/bank-lib/taler-fakebank-run.c | 29 +++++++++++++++++++++++++++--
 src/include/taler_fakebank_lib.h  |  4 +++-
 3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 0a18c521..4ad1be92 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -489,6 +489,12 @@ struct TALER_FAKEBANK_Handle
    */
   pthread_mutex_t big_lock;
 
+  /**
+   * How much money should be put into new accounts
+   * on /register.
+   */
+  struct TALER_Amount signup_bonus;
+
   /**
    * Current transaction counter.
    */
@@ -3432,6 +3438,7 @@ post_testing_register (struct TALER_FAKEBANK_Handle *h,
                             username,
                             username);
       acc->password = GNUNET_strdup (password);
+      acc->balance = h->signup_bonus; /* magic money creation! */
     }
     return TALER_MHD_reply_static (connection,
                                    MHD_HTTP_NO_CONTENT,
@@ -4080,12 +4087,17 @@ TALER_FAKEBANK_start2 (uint16_t port,
                        uint64_t ram_limit,
                        unsigned int num_threads)
 {
+  struct TALER_Amount zero;
+
+  TALER_amount_set_zero (currency,
+                         &zero);
   return TALER_FAKEBANK_start3 ("localhost",
                                 port,
                                 NULL,
                                 currency,
                                 ram_limit,
-                                num_threads);
+                                num_threads,
+                                &zero);
 }
 
 
@@ -4095,7 +4107,8 @@ TALER_FAKEBANK_start3 (const char *hostname,
                        const char *exchange_url,
                        const char *currency,
                        uint64_t ram_limit,
-                       unsigned int num_threads)
+                       unsigned int num_threads,
+                       const struct TALER_Amount *signup_bonus)
 {
   struct TALER_FAKEBANK_Handle *h;
 
@@ -4107,7 +4120,14 @@ TALER_FAKEBANK_start3 (const char *hostname,
     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__
diff --git a/src/bank-lib/taler-fakebank-run.c 
b/src/bank-lib/taler-fakebank-run.c
index d77d6b3d..c15145ec 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.
@@ -161,12 +165,28 @@ run (void *cls,
       go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
     TALER_MHD_setup (go);
   }
+  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);
@@ -206,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/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h
index 54af1545..6b34f473 100644
--- a/src/include/taler_fakebank_lib.h
+++ b/src/include/taler_fakebank_lib.h
@@ -91,6 +91,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
  * @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 *
@@ -99,7 +100,8 @@ TALER_FAKEBANK_start3 (const char *hostname,
                        const char *exchange_url,
                        const char *currency,
                        uint64_t ram_limit,
-                       unsigned int num_threads);
+                       unsigned int num_threads,
+                       const struct TALER_Amount *signup_bonus);
 
 
 /**

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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