aboutsummaryrefslogtreecommitdiff
path: root/src/exchange-lib
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-02-21 12:23:45 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-02-21 12:23:45 +0100
commit377f35fd7da097372ca494b8b30569b73336cdf2 (patch)
tree99435674f5e02b0b2307e9ef0f3f003efd7ff6d5 /src/exchange-lib
parentb09bd97c3b5cfa2356d05c6a5d2b7d2cf08fa76f (diff)
adding command to wire transfer to exchange by
reading a merchant instance's (reserve tip) private key in order to construct the subject.
Diffstat (limited to 'src/exchange-lib')
-rw-r--r--src/exchange-lib/testing_api_cmd_fakebank_transfer.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c
index 1093918fd..2fa67f18e 100644
--- a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c
+++ b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c
@@ -107,6 +107,19 @@ struct FakebankTransferState
* Exchange URL.
*/
const char *exchange_url;
+
+ /**
+ * Merchant instance. Sometimes used to get the tip reserve
+ * private key by reading the appropriate config section.
+ */
+ const char *instance;
+
+ /**
+ * Configuration filename. Used to get the tip reserve key
+ * filename, used to obtain a public key to write in the
+ * transfer subject.
+ */
+ const char *config_filename;
};
@@ -198,11 +211,58 @@ fakebank_transfer_run (void *cls,
}
else
{
+ if (NULL != fts->instance)
+ {
+ GNUNET_assert (NULL != fts->config_filename);
+ char *section;
+ char *keys;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_asprintf (&section,
+ "merchant-instance-%s",
+ fts->instance);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string
+ (cfg,
+ section,
+ "TIP_RESERVE_PRIV_FILENAME",
+ &keys))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Configuration fails to specify reserve"
+ " private key filename in section %s\n",
+ section);
+ GNUNET_free (section);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ priv = GNUNET_CRYPTO_eddsa_key_create_from_file (keys);
+ if (NULL == priv)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "TIP_RESERVE_PRIV_FILENAME",
+ "Failed to read private key");
+ GNUNET_free (keys);
+ GNUNET_free (section);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ fts->reserve_priv.eddsa_priv = *priv;
+ GNUNET_free (priv);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ }
+ else
+ {
+ /* No referenced reserve, no instance to take priv
+ * from, no explicit subject given: create new key! */
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
priv = GNUNET_CRYPTO_eddsa_key_create ();
fts->reserve_priv.eddsa_priv = *priv;
GNUNET_free (priv);
+ }
}
GNUNET_CRYPTO_eddsa_key_get_public
(&fts->reserve_priv.eddsa_priv, &reserve_pub.eddsa_pub);
@@ -431,4 +491,52 @@ TALER_TESTING_cmd_fakebank_transfer_with_ref
}
+/**
+ * Create fakebank_transfer command with custom subject.
+ *
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_fakebank_transfer_with_instance
+ (const char *label,
+ const char *amount,
+ const char *bank_url,
+ uint64_t debit_account_no,
+ uint64_t credit_account_no,
+ const char *auth_username,
+ const char *auth_password,
+ const char *instance,
+ const char *exchange_url,
+ const char *config_filename)
+{
+ struct TALER_TESTING_Command cmd;
+ struct FakebankTransferState *fts;
+
+ fts = GNUNET_new (struct FakebankTransferState);
+ fts->bank_url = bank_url;
+ fts->credit_account_no = credit_account_no;
+ fts->debit_account_no = debit_account_no;
+ fts->auth_username = auth_username;
+ fts->auth_password = auth_password;
+ fts->instance = instance;
+ fts->exchange_url = exchange_url;
+ fts->config_filename = config_filename;
+ if (GNUNET_OK !=
+ TALER_string_to_amount (amount,
+ &fts->amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %s\n",
+ amount,
+ label);
+ GNUNET_assert (0);
+ }
+ cmd.cls = fts;
+ cmd.label = label;
+ cmd.run = &fakebank_transfer_run;
+ cmd.cleanup = &fakebank_transfer_cleanup;
+ cmd.traits = &fakebank_transfer_traits;
+ return cmd;
+}
+
+
/* end of testing_api_cmd_fakebank_transfer.c */