2016-04-17 23:14:23 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2020-01-11 15:19:56 +01:00
|
|
|
(C) 2016-2020 Taler Systems SA
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2016-07-07 17:55:25 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2016-04-17 23:14:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-04-20 07:49:56 +02:00
|
|
|
* @file include/taler_fakebank_lib.h
|
2016-04-17 23:14:23 +02:00
|
|
|
* @brief API for a library that fakes being a Taler bank
|
|
|
|
* @author Christian Grothoff <christian@grothoff.org>
|
|
|
|
*/
|
2016-06-08 11:35:28 +02:00
|
|
|
#ifndef TALER_FAKEBANK_H
|
|
|
|
#define TALER_FAKEBANK_H
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
#include "taler_util.h"
|
|
|
|
#include <gnunet/gnunet_json_lib.h>
|
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <microhttpd.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle for the fake bank.
|
|
|
|
*/
|
2016-06-08 11:35:28 +02:00
|
|
|
struct TALER_FAKEBANK_Handle;
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-01-18 14:36:49 +01:00
|
|
|
* Start the fake bank. The fake bank will, like the normal bank, listen for
|
|
|
|
* requests for /admin/add/incoming and /transfer. However, instead of
|
|
|
|
* executing or storing those requests, it will simply allow querying whether
|
|
|
|
* such a request has been made via #TALER_FAKEBANK_check_debit() and
|
|
|
|
* #TALER_FAKEBANK_check_credit() as well as the history API.
|
2016-04-17 23:14:23 +02:00
|
|
|
*
|
|
|
|
* This is useful for writing testcases to check whether the exchange
|
|
|
|
* would have issued the correct wire transfer orders.
|
|
|
|
*
|
|
|
|
* @param port port to listen to
|
|
|
|
* @return NULL on error
|
|
|
|
*/
|
2016-06-08 11:35:28 +02:00
|
|
|
struct TALER_FAKEBANK_Handle *
|
|
|
|
TALER_FAKEBANK_start (uint16_t port);
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that no wire transfers were ordered (or at least none
|
2020-01-18 16:41:24 +01:00
|
|
|
* that have not been taken care of via #TALER_FAKEBANK_check_debit()
|
|
|
|
* or #TALER_FAKEBANK_check_credit()).
|
2016-04-17 23:14:23 +02:00
|
|
|
* If any transactions are onrecord, return #GNUNET_SYSERR.
|
|
|
|
*
|
|
|
|
* @param h bank instance
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
int
|
2016-06-08 11:35:28 +02:00
|
|
|
TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
|
2017-06-11 15:25:59 +02:00
|
|
|
/**
|
2020-01-12 17:58:17 +01:00
|
|
|
* Tell the fakebank to create another wire transfer *from* an exchange.
|
2017-06-11 15:25:59 +02:00
|
|
|
*
|
|
|
|
* @param h fake bank handle
|
|
|
|
* @param debit_account account to debit
|
|
|
|
* @param credit_account account to credit
|
|
|
|
* @param amount amount to transfer
|
|
|
|
* @param subject wire transfer subject to use
|
|
|
|
* @param exchange_base_url exchange URL
|
2020-01-13 22:27:49 +01:00
|
|
|
* @param request_uid unique number to make the request unique, or NULL to create one
|
2020-01-21 16:13:22 +01:00
|
|
|
* @param[out] ret_row_id pointer to store the row ID of this transaction
|
|
|
|
* @return GNUNET_YES if the transfer was successful,
|
|
|
|
* GNUNET_SYSERR if the request_uid was reused for a different transfer
|
2017-06-11 15:25:59 +02:00
|
|
|
*/
|
2020-01-21 16:13:22 +01:00
|
|
|
int
|
2017-06-11 15:25:59 +02:00
|
|
|
TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
|
2020-01-11 15:19:56 +01:00
|
|
|
const char *debit_account,
|
|
|
|
const char *credit_account,
|
2017-06-11 15:25:59 +02:00
|
|
|
const struct TALER_Amount *amount,
|
2020-01-12 17:58:17 +01:00
|
|
|
const struct
|
|
|
|
TALER_WireTransferIdentifierRawP *subject,
|
2020-01-13 22:27:49 +01:00
|
|
|
const char *exchange_base_url,
|
2020-01-21 16:13:22 +01:00
|
|
|
const struct GNUNET_HashCode *request_uid,
|
|
|
|
uint64_t *ret_row_id);
|
2017-06-11 15:25:59 +02:00
|
|
|
|
|
|
|
|
2020-01-12 17:58:17 +01:00
|
|
|
/**
|
|
|
|
* Tell the fakebank to create another wire transfer *to* an exchange.
|
|
|
|
*
|
|
|
|
* @param h fake bank handle
|
|
|
|
* @param debit_account account to debit
|
|
|
|
* @param credit_account account to credit
|
|
|
|
* @param amount amount to transfer
|
|
|
|
* @param reserve_pub reserve public key to use in subject
|
|
|
|
* @return serial_id of the transfer
|
|
|
|
*/
|
|
|
|
uint64_t
|
|
|
|
TALER_FAKEBANK_make_admin_transfer (struct TALER_FAKEBANK_Handle *h,
|
|
|
|
const char *debit_account,
|
|
|
|
const char *credit_account,
|
|
|
|
const struct TALER_Amount *amount,
|
|
|
|
const struct
|
|
|
|
TALER_ReservePublicKeyP *reserve_pub);
|
|
|
|
|
|
|
|
|
2016-04-17 23:14:23 +02:00
|
|
|
/**
|
|
|
|
* Check that the @a want_amount was transferred from the @a
|
2017-06-11 15:25:59 +02:00
|
|
|
* want_debit to the @a want_credit account. If so, set the @a subject
|
2016-04-17 23:14:23 +02:00
|
|
|
* to the transfer identifier and remove the transaction from the
|
|
|
|
* list. If the transaction was not recorded, return #GNUNET_SYSERR.
|
|
|
|
*
|
|
|
|
* @param h bank instance
|
|
|
|
* @param want_amount transfer amount desired
|
|
|
|
* @param want_debit account that should have been debited
|
|
|
|
* @param want_debit account that should have been credited
|
2017-03-02 06:26:12 +01:00
|
|
|
* @param exchange_base_url expected base URL of the exchange,
|
|
|
|
* i.e. "https://example.com/"; may include a port
|
2020-01-12 18:09:41 +01:00
|
|
|
* @param[out] wtid set to the wire transfer identifier
|
2016-04-17 23:14:23 +02:00
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
int
|
2020-01-12 17:58:17 +01:00
|
|
|
TALER_FAKEBANK_check_debit (struct TALER_FAKEBANK_Handle *h,
|
|
|
|
const struct TALER_Amount *want_amount,
|
|
|
|
const char *want_debit,
|
|
|
|
const char *want_credit,
|
|
|
|
const char *exchange_base_url,
|
2020-01-12 18:09:41 +01:00
|
|
|
struct TALER_WireTransferIdentifierRawP *wtid);
|
2020-01-12 17:58:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the @a want_amount was transferred from the @a want_debit to the
|
|
|
|
* @a want_credit account with the @a subject. If so, remove the transaction
|
|
|
|
* from the list. If the transaction was not recorded, return #GNUNET_SYSERR.
|
|
|
|
*
|
|
|
|
* @param h bank instance
|
|
|
|
* @param want_amount transfer amount desired
|
|
|
|
* @param want_debit account that should have been debited
|
|
|
|
* @param want_debit account that should have been credited
|
|
|
|
* @param reserve_pub reserve public key expected in wire subject
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle *h,
|
|
|
|
const struct TALER_Amount *want_amount,
|
|
|
|
const char *want_debit,
|
|
|
|
const char *want_credit,
|
|
|
|
const struct TALER_ReservePublicKeyP *reserve_pub);
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop running the fake bank.
|
|
|
|
*
|
|
|
|
* @param h bank to stop
|
|
|
|
*/
|
|
|
|
void
|
2016-06-08 11:35:28 +02:00
|
|
|
TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h);
|
2016-04-17 23:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|