-enable signup bonus with fakebank

This commit is contained in:
Christian Grothoff 2022-08-25 19:52:53 +02:00
parent 8322527536
commit ecae3c26dd
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 52 additions and 5 deletions

View File

@ -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__

View File

@ -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;

View File

@ -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);
/**