diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-08-25 19:52:53 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-08-25 19:52:53 +0200 |
commit | ecae3c26dd054f8c17e335622036a1e38a48ed9a (patch) | |
tree | 702287797c2eae66f23b38c293f5c04027cf85ac | |
parent | 83225275361a92390f92245e0edb04e1c675dc91 (diff) | |
download | exchange-ecae3c26dd054f8c17e335622036a1e38a48ed9a.tar.xz |
-enable signup bonus with fakebank
-rw-r--r-- | src/bank-lib/fakebank.c | 24 | ||||
-rw-r--r-- | src/bank-lib/taler-fakebank-run.c | 29 | ||||
-rw-r--r-- | 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 0a18c5217..4ad1be92a 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -490,6 +490,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. */ uint64_t serial_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 d77d6b3d5..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. @@ -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 54af1545b..6b34f4730 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); /** |