2020-01-16 12:02:19 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2018 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
|
|
|
|
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 TALER; see the file COPYING. If not,
|
|
|
|
see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
2020-01-19 15:23:19 +01:00
|
|
|
* @file testing/testing_api_cmd_insert_deposit.c
|
2020-01-16 12:02:19 +01:00
|
|
|
* @brief deposit a coin directly into the database.
|
|
|
|
* @author Marcello Stanisci
|
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
2020-01-16 18:37:07 +01:00
|
|
|
#include "taler_util.h"
|
2020-01-16 12:02:19 +01:00
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include "taler_signatures.h"
|
|
|
|
#include "taler_testing_lib.h"
|
2020-01-16 18:37:07 +01:00
|
|
|
#include "taler_exchangedb_plugin.h"
|
2020-01-16 12:02:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State for a "insert-deposit" CMD.
|
|
|
|
*/
|
|
|
|
struct InsertDepositState
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration file used by the command.
|
|
|
|
*/
|
2020-01-16 18:37:07 +01:00
|
|
|
const struct TALER_TESTING_DatabaseConnection *dbc;
|
2020-01-16 12:13:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Human-readable name of the shop.
|
|
|
|
*/
|
|
|
|
const char *merchant_name;
|
|
|
|
|
|
|
|
/**
|
2020-01-17 20:27:17 +01:00
|
|
|
* Merchant account name (NOT a payto-URI).
|
2020-01-16 12:13:11 +01:00
|
|
|
*/
|
|
|
|
const char *merchant_account;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deadline before which the aggregator should
|
|
|
|
* send the payment to the merchant.
|
|
|
|
*/
|
2020-01-16 18:37:07 +01:00
|
|
|
struct GNUNET_TIME_Relative wire_deadline;
|
2020-01-16 12:13:11 +01:00
|
|
|
|
2020-05-07 20:22:02 +02:00
|
|
|
/**
|
|
|
|
* When did the exchange receive the deposit?
|
|
|
|
*/
|
|
|
|
struct GNUNET_TIME_Absolute exchange_timestamp;
|
|
|
|
|
2020-01-16 12:13:11 +01:00
|
|
|
/**
|
|
|
|
* Amount to deposit, inclusive of deposit fee.
|
|
|
|
*/
|
|
|
|
const char *amount_with_fee;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deposit fee.
|
|
|
|
*/
|
|
|
|
const char *deposit_fee;
|
2020-01-16 12:02:19 +01:00
|
|
|
};
|
|
|
|
|
2020-01-16 18:37:07 +01:00
|
|
|
/**
|
|
|
|
* Setup (fake) information about a coin used in deposit.
|
|
|
|
*
|
|
|
|
* @param[out] issue information to initialize with "valid" data
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fake_issue (struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue)
|
|
|
|
{
|
2021-08-06 10:20:58 +02:00
|
|
|
struct GNUNET_TIME_Absolute now;
|
|
|
|
|
|
|
|
memset (issue,
|
|
|
|
0,
|
|
|
|
sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP));
|
|
|
|
now = GNUNET_TIME_absolute_get ();
|
|
|
|
(void) GNUNET_TIME_round_abs (&now);
|
|
|
|
issue->properties.start
|
|
|
|
= GNUNET_TIME_absolute_hton (now);
|
|
|
|
issue->properties.expire_withdraw
|
|
|
|
= GNUNET_TIME_absolute_hton (
|
|
|
|
GNUNET_TIME_absolute_add (now,
|
|
|
|
GNUNET_TIME_UNIT_MINUTES));
|
|
|
|
issue->properties.expire_deposit
|
|
|
|
= GNUNET_TIME_absolute_hton (
|
|
|
|
GNUNET_TIME_absolute_add (now,
|
|
|
|
GNUNET_TIME_UNIT_HOURS));
|
|
|
|
issue->properties.expire_legal
|
|
|
|
= GNUNET_TIME_absolute_hton (
|
|
|
|
GNUNET_TIME_absolute_add (now,
|
|
|
|
GNUNET_TIME_UNIT_DAYS));
|
2020-01-16 18:37:07 +01:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount_nbo ("EUR:1",
|
|
|
|
&issue->properties.value));
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount_nbo ("EUR:0.1",
|
|
|
|
&issue->properties.fee_withdraw));
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount_nbo ("EUR:0.1",
|
|
|
|
&issue->properties.fee_deposit));
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount_nbo ("EUR:0.1",
|
|
|
|
&issue->properties.fee_refresh));
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount_nbo ("EUR:0.1",
|
|
|
|
&issue->properties.fee_refund));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 12:02:19 +01:00
|
|
|
/**
|
|
|
|
* Run the command.
|
|
|
|
*
|
|
|
|
* @param cls closure.
|
|
|
|
* @param cmd the commaind being run.
|
|
|
|
* @param is interpreter state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
insert_deposit_run (void *cls,
|
|
|
|
const struct TALER_TESTING_Command *cmd,
|
|
|
|
struct TALER_TESTING_Interpreter *is)
|
|
|
|
{
|
2020-01-16 12:54:05 +01:00
|
|
|
struct InsertDepositState *ids = cls;
|
2020-01-16 18:37:07 +01:00
|
|
|
struct TALER_EXCHANGEDB_Deposit deposit;
|
|
|
|
struct TALER_MerchantPrivateKeyP merchant_priv;
|
|
|
|
struct TALER_EXCHANGEDB_DenominationKeyInformationP issue;
|
2021-11-05 14:00:10 +01:00
|
|
|
struct TALER_DenominationPublicKey dpk;
|
|
|
|
struct TALER_DenominationPrivateKey denom_priv;
|
2020-01-16 18:37:07 +01:00
|
|
|
|
2021-11-19 10:57:27 +01:00
|
|
|
(void) cmd;
|
2020-01-16 18:37:07 +01:00
|
|
|
// prepare and store issue first.
|
|
|
|
fake_issue (&issue);
|
2021-11-05 14:00:10 +01:00
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_denom_priv_create (&denom_priv,
|
|
|
|
&dpk,
|
|
|
|
TALER_DENOMINATION_RSA,
|
|
|
|
1024));
|
2021-10-27 21:59:04 +02:00
|
|
|
TALER_denom_pub_hash (&dpk,
|
|
|
|
&issue.properties.denom_hash);
|
2020-01-16 18:37:07 +01:00
|
|
|
|
|
|
|
if ( (GNUNET_OK !=
|
|
|
|
ids->dbc->plugin->start (ids->dbc->plugin->cls,
|
|
|
|
"talertestinglib: denomination insertion")) ||
|
|
|
|
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
|
|
|
ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls,
|
|
|
|
&dpk,
|
|
|
|
&issue)) ||
|
|
|
|
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
|
2021-08-23 00:00:32 +02:00
|
|
|
ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
|
2020-01-16 18:37:07 +01:00
|
|
|
{
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
2021-11-05 14:00:10 +01:00
|
|
|
TALER_denom_pub_free (&dpk);
|
|
|
|
TALER_denom_priv_free (&denom_priv);
|
2020-01-16 18:37:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-18 13:57:47 +01:00
|
|
|
/* prepare and store deposit now. */
|
2020-01-16 18:37:07 +01:00
|
|
|
memset (&deposit,
|
|
|
|
0,
|
2020-01-16 22:40:12 +01:00
|
|
|
sizeof (deposit));
|
2020-01-16 18:37:07 +01:00
|
|
|
|
|
|
|
GNUNET_CRYPTO_kdf (&merchant_priv,
|
|
|
|
sizeof (struct TALER_MerchantPrivateKeyP),
|
|
|
|
"merchant-priv",
|
|
|
|
strlen ("merchant-priv"),
|
|
|
|
ids->merchant_name,
|
|
|
|
strlen (ids->merchant_name),
|
|
|
|
NULL,
|
2020-01-16 22:40:12 +01:00
|
|
|
0);
|
2020-01-16 18:37:07 +01:00
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
|
|
|
|
&deposit.merchant_pub.eddsa_pub);
|
|
|
|
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
2021-10-27 21:59:04 +02:00
|
|
|
&deposit.h_contract_terms.hash);
|
2020-01-16 18:37:07 +01:00
|
|
|
if ( (GNUNET_OK !=
|
|
|
|
TALER_string_to_amount (ids->amount_with_fee,
|
|
|
|
&deposit.amount_with_fee)) ||
|
|
|
|
(GNUNET_OK !=
|
|
|
|
TALER_string_to_amount (ids->deposit_fee,
|
|
|
|
&deposit.deposit_fee)) )
|
|
|
|
{
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
2021-11-05 14:00:10 +01:00
|
|
|
TALER_denom_pub_free (&dpk);
|
|
|
|
TALER_denom_priv_free (&denom_priv);
|
2020-01-16 18:37:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-27 21:59:04 +02:00
|
|
|
TALER_denom_pub_hash (&dpk,
|
|
|
|
&deposit.coin.denom_pub_hash);
|
2020-07-08 21:24:10 +02:00
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
&deposit.coin.coin_pub,
|
|
|
|
sizeof (deposit.coin.coin_pub));
|
2021-11-06 16:04:26 +01:00
|
|
|
{
|
|
|
|
struct TALER_CoinPubHash c_hash;
|
|
|
|
struct TALER_PlanchetDetail pd;
|
|
|
|
struct TALER_BlindedDenominationSignature bds;
|
|
|
|
union TALER_DenominationBlindingKeyP bks;
|
|
|
|
|
|
|
|
TALER_blinding_secret_create (&bks);
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_denom_blind (&dpk,
|
|
|
|
&bks,
|
2021-11-16 14:43:54 +01:00
|
|
|
NULL, /* FIXME-Oec */
|
2021-11-06 16:04:26 +01:00
|
|
|
&deposit.coin.coin_pub,
|
|
|
|
&c_hash,
|
|
|
|
&pd.coin_ev,
|
|
|
|
&pd.coin_ev_size));
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_denom_sign_blinded (&bds,
|
|
|
|
&denom_priv,
|
|
|
|
pd.coin_ev,
|
|
|
|
pd.coin_ev_size));
|
|
|
|
GNUNET_free (pd.coin_ev);
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_denom_sig_unblind (&deposit.coin.denom_sig,
|
|
|
|
&bds,
|
|
|
|
&bks,
|
|
|
|
&dpk));
|
|
|
|
TALER_blinded_denom_sig_free (&bds);
|
|
|
|
}
|
2021-10-30 19:28:11 +02:00
|
|
|
GNUNET_asprintf (&deposit.receiver_wire_account,
|
|
|
|
"payto://x-taler-bank/localhost/%s",
|
|
|
|
ids->merchant_account);
|
|
|
|
memset (&deposit.wire_salt,
|
|
|
|
46,
|
|
|
|
sizeof (deposit.wire_salt));
|
2020-01-16 18:37:07 +01:00
|
|
|
deposit.timestamp = GNUNET_TIME_absolute_get ();
|
2020-07-08 21:24:10 +02:00
|
|
|
(void) GNUNET_TIME_round_abs (&deposit.timestamp);
|
|
|
|
deposit.wire_deadline = GNUNET_TIME_relative_to_absolute (ids->wire_deadline);
|
|
|
|
(void) GNUNET_TIME_round_abs (&deposit.wire_deadline);
|
2020-01-16 18:37:07 +01:00
|
|
|
|
|
|
|
/* finally, actually perform the DB operation */
|
|
|
|
if ( (GNUNET_OK !=
|
|
|
|
ids->dbc->plugin->start (ids->dbc->plugin->cls,
|
|
|
|
"libtalertesting: insert deposit")) ||
|
|
|
|
(0 >
|
|
|
|
ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls,
|
|
|
|
&deposit.coin)) ||
|
|
|
|
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
|
|
|
ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls,
|
2020-05-07 20:22:02 +02:00
|
|
|
ids->exchange_timestamp,
|
2020-01-16 18:37:07 +01:00
|
|
|
&deposit)) ||
|
|
|
|
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
|
2021-08-23 00:00:32 +02:00
|
|
|
ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
|
2020-01-16 18:37:07 +01:00
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
2021-08-23 00:00:32 +02:00
|
|
|
ids->dbc->plugin->rollback (ids->dbc->plugin->cls);
|
2021-10-30 19:28:11 +02:00
|
|
|
GNUNET_free (deposit.receiver_wire_account);
|
2021-11-05 14:00:10 +01:00
|
|
|
TALER_denom_pub_free (&dpk);
|
|
|
|
TALER_denom_priv_free (&denom_priv);
|
2020-01-16 18:37:07 +01:00
|
|
|
TALER_TESTING_interpreter_fail (is);
|
2021-10-30 19:28:11 +02:00
|
|
|
return;
|
2020-01-16 18:37:07 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 21:59:04 +02:00
|
|
|
TALER_denom_sig_free (&deposit.coin.denom_sig);
|
|
|
|
TALER_denom_pub_free (&dpk);
|
2021-11-05 14:00:10 +01:00
|
|
|
TALER_denom_priv_free (&denom_priv);
|
2021-10-30 19:28:11 +02:00
|
|
|
GNUNET_free (deposit.receiver_wire_account);
|
2020-01-16 18:37:07 +01:00
|
|
|
TALER_TESTING_interpreter_next (is);
|
2020-01-16 12:02:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the state of a "auditor-dbinit" CMD, and possibly kills its
|
|
|
|
* process if it did not terminate correctly.
|
|
|
|
*
|
|
|
|
* @param cls closure.
|
|
|
|
* @param cmd the command being freed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
insert_deposit_cleanup (void *cls,
|
|
|
|
const struct TALER_TESTING_Command *cmd)
|
|
|
|
{
|
2020-01-16 18:37:07 +01:00
|
|
|
struct InsertDepositState *ids = cls;
|
2020-01-16 22:40:12 +01:00
|
|
|
|
2021-11-19 10:57:27 +01:00
|
|
|
(void) cmd;
|
2020-01-16 18:37:07 +01:00
|
|
|
GNUNET_free (ids);
|
2020-01-16 12:02:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct TALER_TESTING_Command
|
2020-05-07 20:22:02 +02:00
|
|
|
TALER_TESTING_cmd_insert_deposit (
|
|
|
|
const char *label,
|
|
|
|
const struct TALER_TESTING_DatabaseConnection *dbc,
|
|
|
|
const char *merchant_name,
|
|
|
|
const char *merchant_account,
|
|
|
|
struct GNUNET_TIME_Absolute exchange_timestamp,
|
|
|
|
struct GNUNET_TIME_Relative wire_deadline,
|
|
|
|
const char *amount_with_fee,
|
|
|
|
const char *deposit_fee)
|
2020-01-16 12:02:19 +01:00
|
|
|
{
|
2020-01-16 12:54:05 +01:00
|
|
|
struct InsertDepositState *ids;
|
2020-01-16 12:02:19 +01:00
|
|
|
|
2020-05-07 20:22:02 +02:00
|
|
|
GNUNET_TIME_round_abs (&exchange_timestamp);
|
2020-01-16 12:54:05 +01:00
|
|
|
ids = GNUNET_new (struct InsertDepositState);
|
2020-01-16 18:37:07 +01:00
|
|
|
ids->dbc = dbc;
|
2020-01-16 12:54:05 +01:00
|
|
|
ids->merchant_name = merchant_name;
|
|
|
|
ids->merchant_account = merchant_account;
|
2020-05-07 20:22:02 +02:00
|
|
|
ids->exchange_timestamp = exchange_timestamp;
|
2020-01-16 12:54:05 +01:00
|
|
|
ids->wire_deadline = wire_deadline;
|
|
|
|
ids->amount_with_fee = amount_with_fee;
|
|
|
|
ids->deposit_fee = deposit_fee;
|
2020-01-16 12:13:11 +01:00
|
|
|
|
2020-01-18 13:57:47 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Command cmd = {
|
|
|
|
.cls = ids,
|
|
|
|
.label = label,
|
|
|
|
.run = &insert_deposit_run,
|
2021-10-27 21:59:04 +02:00
|
|
|
.cleanup = &insert_deposit_cleanup
|
2020-01-18 13:57:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
2020-01-16 12:02:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 18:37:07 +01:00
|
|
|
/* end of testing_api_cmd_insert_deposit.c */
|