commit 99686e722a0ec53fa0e752f5a2186a1ed35bff2f
parent 5e26ac4a6a1f617a2d6e7c2eab3330ed794a14b0
Author: Manuel Geissbühler <manuel@debian>
Date: Mon, 30 Dec 2024 19:42:44 +0100
added some prototypes for bank communication
Diffstat:
19 files changed, 1553 insertions(+), 8 deletions(-)
diff --git a/build/CMakeCache.txt b/build/CMakeCache.txt
@@ -256,6 +256,9 @@ PKG_CONFIG_ARGN:STRING=
//pkg-config executable
PKG_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/pkg-config
+//Dependencies for the target
+bank_LIB_DEPENDS:STATIC=general;talerjson;general;talercurl;general;talerutil;general;talerbank;general;gnunetutil;general;gnunetcurl;general;gnunetjson;general;jansson;general;curl;
+
//Value Computed by CMake
cash2ecash_BINARY_DIR:STATIC=/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build
diff --git a/build/Makefile b/build/Makefile
@@ -188,6 +188,19 @@ cashacceptor/fast:
.PHONY : cashacceptor/fast
#=============================================================================
+# Target rules for targets named bank
+
+# Build rule for target.
+bank: cmake_check_build_system
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 bank
+.PHONY : bank
+
+# fast build rule for target.
+bank/fast:
+ $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/build
+.PHONY : bank/fast
+
+#=============================================================================
# Target rules for targets named lvgl
# Build rule for target.
@@ -301,6 +314,7 @@ help:
@echo "... install/strip"
@echo "... list_install_components"
@echo "... rebuild_cache"
+ @echo "... bank"
@echo "... cash2ecash"
@echo "... cashacceptor"
@echo "... gui"
diff --git a/build/bank/Makefile b/build/bank/Makefile
@@ -161,6 +161,68 @@ depend:
cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
+# Convenience name for target.
+bank/CMakeFiles/bank.dir/rule:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 bank/CMakeFiles/bank.dir/rule
+.PHONY : bank/CMakeFiles/bank.dir/rule
+
+# Convenience name for target.
+bank: bank/CMakeFiles/bank.dir/rule
+.PHONY : bank
+
+# fast build rule for target.
+bank/fast:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/build
+.PHONY : bank/fast
+
+bank_api_account_withdrawal.o: bank_api_account_withdrawal.c.o
+.PHONY : bank_api_account_withdrawal.o
+
+# target to build an object file
+bank_api_account_withdrawal.c.o:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_api_account_withdrawal.c.o
+.PHONY : bank_api_account_withdrawal.c.o
+
+bank_api_account_withdrawal.i: bank_api_account_withdrawal.c.i
+.PHONY : bank_api_account_withdrawal.i
+
+# target to preprocess a source file
+bank_api_account_withdrawal.c.i:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_api_account_withdrawal.c.i
+.PHONY : bank_api_account_withdrawal.c.i
+
+bank_api_account_withdrawal.s: bank_api_account_withdrawal.c.s
+.PHONY : bank_api_account_withdrawal.s
+
+# target to generate assembly for a file
+bank_api_account_withdrawal.c.s:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_api_account_withdrawal.c.s
+.PHONY : bank_api_account_withdrawal.c.s
+
+bank_lib.o: bank_lib.c.o
+.PHONY : bank_lib.o
+
+# target to build an object file
+bank_lib.c.o:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_lib.c.o
+.PHONY : bank_lib.c.o
+
+bank_lib.i: bank_lib.c.i
+.PHONY : bank_lib.i
+
+# target to preprocess a source file
+bank_lib.c.i:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_lib.c.i
+.PHONY : bank_lib.c.i
+
+bank_lib.s: bank_lib.c.s
+.PHONY : bank_lib.s
+
+# target to generate assembly for a file
+bank_lib.c.s:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f bank/CMakeFiles/bank.dir/build.make bank/CMakeFiles/bank.dir/bank_lib.c.s
+.PHONY : bank_lib.c.s
+
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@@ -173,6 +235,13 @@ help:
@echo "... install/strip"
@echo "... list_install_components"
@echo "... rebuild_cache"
+ @echo "... bank"
+ @echo "... bank_api_account_withdrawal.o"
+ @echo "... bank_api_account_withdrawal.i"
+ @echo "... bank_api_account_withdrawal.s"
+ @echo "... bank_lib.o"
+ @echo "... bank_lib.i"
+ @echo "... bank_lib.s"
.PHONY : help
diff --git a/build/compile_commands.json b/build/compile_commands.json
@@ -15,6 +15,16 @@
"file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/cashacceptor/dg600f.cpp"
},
{
+ "directory": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/bank",
+ "command": "/usr/bin/cc -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/include -g -o CMakeFiles/bank.dir/bank_lib.c.o -c /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/bank/bank_lib.c",
+ "file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/bank/bank_lib.c"
+},
+{
+ "directory": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/bank",
+ "command": "/usr/bin/cc -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/include -g -o CMakeFiles/bank.dir/bank_api_account_withdrawal.c.o -c /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/bank/bank_api_account_withdrawal.c",
+ "file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/bank/bank_api_account_withdrawal.c"
+},
+{
"directory": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/extern/lvgl",
"command": "/usr/bin/cc -DLV_CONF_INCLUDE_SIMPLE -DLV_LVGL_H_INCLUDE_SIMPLE -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/include -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/extern -I/usr/include/libdrm -isystem /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/extern/lvgl -isystem /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/extern/lvgl -g -std=gnu99 -o CMakeFiles/lvgl.dir/src/core/lv_group.c.o -c /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/extern/lvgl/src/core/lv_group.c",
"file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/extern/lvgl/src/core/lv_group.c"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -22,4 +22,5 @@ add_subdirectory(utils)
target_link_libraries(cash2ecash PRIVATE cashacceptor
utils
gui
- lvgl)
+ lvgl
+ bank)
diff --git a/src/bank/#bankAPI.c# b/src/bank/#bankAPI.c#
@@ -0,0 +1,244 @@
+#include <string.h>
+#include <taler/taler_bank_service.h>
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+#include <stdio.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_bank_service_cash2ecash.h"
+
+
+
+static struct TALER_BANK_AuthenticationData auth;
+static struct GNUNET_CURL_Context *ctx;
+static struct GNUNET_CURL_RescheduleContext *rc;
+static struct TALER_BANK_AccountTokenHandle *ath;
+static struct TALER_BANK_AccountWithdrawalHandle *awh;
+static struct TALER_BANK_AccountWithdrawalConfirmHandle *awch;
+static const char *configfilename = "/home/manuel/.config/taler-exchange.conf";
+static const char *account_section = "bank-accountcredentials-cash2ecash";
+static const char *withdrawal_id;
+static const char *taler_withdraw_uri;
+struct TALER_Amount *testamount;
+struct TALER_Amount *testsuggestedamount;
+
+// Forward Declarations
+static void account_token_cb(void *cls,
+ const struct TALER_BANK_AccountTokenResponse *atr);
+static void account_withdrawal_cb(void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr);
+static void account_withdrawal_confirm_cb(
+ void *cls, const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr);
+
+
+
+
+
+/**
+ *Callback function for TALER_BANK_account_token
+ */
+static void account_token_cb(void *cls, const struct TALER_BANK_AccountTokenResponse *atr){
+ (void) cls;
+
+ ath = NULL;
+ switch (atr->http_status) {
+ case 0:
+ fprintf(stderr, "Failed to obtain HTTP reply from `%s'\n",
+ auth.wire_gateway_url);
+ break;
+ default:
+ fprintf (stderr,
+ "Failed to obtain debit history from `%s': HTTP status %u (%s)\n",
+ auth.wire_gateway_url,
+ atr->http_status,
+ TALER_ErrorCode_get_hint (atr->ec));
+ if (NULL != atr->response)
+ json_dumpf (atr->response,
+ stderr,
+ JSON_INDENT (2));
+ break;
+ }
+
+ //Switch Authentification method to Bearer and add Token
+ GNUNET_free(auth.details.basic.password);
+ GNUNET_free(auth.details.basic.username);
+ auth.method = TALER_BANK_AUTH_BEARER;
+ auth.details.bearer.token = GNUNET_strdup(atr->details.ok.access_token);
+
+ //Make Withdrawal request (Do I have to check if the account Token request did allready run completely?)
+
+ awh = TALER_BANK_account_withdrawal(ctx,
+ &auth,
+ "finsteraarhorn",
+ testamount,
+ testsuggestedamount,
+ &account_withdrawal_cb,
+ NULL);
+
+ if (NULL == awh){
+ printf("error with awh");
+ GNUNET_SCHEDULER_shutdown();
+ }
+
+ //GNUNET_SCHEDULER_shutdown();
+}
+
+
+
+/**
+ *Callback function for TALER_BANK_account_withdrawal
+ */
+static void account_withdrawal_cb(void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr){
+ (void) cls;
+ awh = NULL;
+
+ fprintf(stdout, "account withdrawal callback called\n");
+ fprintf(stdout, "%s\n", awr->details.ok.taler_withdraw_uri);
+ json_dumpf (awr->response,
+ stderr,
+ JSON_INDENT (2));
+
+ //Not sure if the correspondign memory is freed somewhere, might be neccessary to strdup and otherwise
+ //take responsibility to free.
+ withdrawal_id = awr->details.ok.withdrawal_id;
+ taler_withdraw_uri = awr->details.ok.taler_withdraw_uri;
+
+ char useserinput[5];
+ scanf("%s",useserinput);
+ if (0 != strcmp("go", useserinput)){
+ printf("error");
+ }
+
+ awch = TALER_BANK_account_withdrawal_confirm(ctx, &auth,
+ "finsteraarhorn",
+ withdrawal_id,
+ testsuggestedamount,
+ &account_withdrawal_confirm_cb,
+ NULL);
+ if (NULL == awch){
+ printf("error with awch");
+ GNUNET_SCHEDULER_shutdown();
+ }
+}
+
+/**
+ *Callback function for TALER_BANK_account_withdrawal_confirm
+ */
+static void account_withdrawal_confirm_cb(void *cls, const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr){
+ (void) cls;
+ awch = NULL;
+
+ fprintf(stderr, "%s", TALER_ErrorCode_get_hint (awcr->ec));
+ fprintf(stdout, "account withdrawal confirmation callback called\n");
+ GNUNET_SCHEDULER_shutdown();
+}
+
+/**
+ *Function to do the cleanup
+ */
+static void do_shutdown(void *cls){
+ (void) cls;
+
+ if(NULL != ath){
+ TALER_BANK_account_token_cancel(ath);
+ }
+
+ if (NULL != awh){
+ TALER_BANK_account_withdrawal_cancel(awh);
+ }
+
+ if (NULL != awch) {
+ TALER_BANK_account_withdrawal_confirm_cancel(awch);
+ }
+
+ if (NULL != ctx){
+ GNUNET_CURL_fini(ctx);
+ }
+
+ if (NULL != rc){
+ GNUNET_CURL_gnunet_rc_destroy(rc);
+ }
+ TALER_BANK_auth_free(&auth);
+}
+
+
+/**
+ *Main Program to be Run trough GNUNET_PROGRAM_run()
+ */
+static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg){
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ (void) cfg;
+
+ GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
+
+ ctx = GNUNET_CURL_init(&GNUNET_CURL_gnunet_scheduler_reschedule, &rc);
+ GNUNET_assert(NULL != ctx);
+ rc = GNUNET_CURL_gnunet_rc_create(ctx);
+
+
+ //Parse Config
+ if (GNUNET_OK != TALER_BANK_auth_parse_cfg(cfg, account_section, &auth)){
+ printf("error parsing authentification Data");
+ }
+
+ //Make Token request
+ struct GNUNET_TIME_Relative duration = {UINT64_MAX};
+ ath = TALER_BANK_account_token(ctx,
+ &auth,
+ "finsteraarhorn",
+ TALER_BANK_TOKEN_SCOPE_READWRITE,
+ true,
+ "this is a description",
+ duration,
+ &account_token_cb,
+ NULL);
+
+ if (NULL == ath){
+ printf("error with ath");
+ GNUNET_SCHEDULER_shutdown();
+ }
+
+ struct TALER_Amount amount;
+ TALER_string_to_amount("KUDOS:3.1415", &amount);
+ testamount = &amount;
+ testsuggestedamount = NULL;
+ printf("currency: %s\n",amount.currency);
+ printf("fraction: %d\n",amount.fraction);
+ printf("value: %ld\n",amount.value);
+
+
+
+}
+
+
+/**
+ *main runs function run() trough GNUNET_PROGRAM_run()
+ */
+int main(int argc,
+ char *const *argv){
+ int retval;
+
+ //Run Program
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ retval = GNUNET_PROGRAM_run(
+ TALER_EXCHANGE_project_data(),
+ argc, argv,
+ "bankapi-test",
+ gettext_noop("Test Function for bankapi"),
+ options,
+ &run, NULL);
+ if (GNUNET_SYSERR == retval)
+ return 3;
+ if (GNUNET_NO == retval)
+ return 0;
+
+ return 0;
+}
+
+
diff --git a/src/bank/#bankCommunication.hpp# b/src/bank/#bankCommunication.hpp#
@@ -0,0 +1,14 @@
+#ifndef BANK_COMMUNICATION_H
+#define BANK_COMMUNICATION_H
+
+#include "taler_bank_service_cash2ecash.h"
+
+class BankCommunication{
+ private:
+ protected:
+ public:
+
+
+};
+
+#endif
diff --git a/src/bank/.#bankCommunication.hpp b/src/bank/.#bankCommunication.hpp
@@ -0,0 +1 @@
+manuel@debian.14713:1735541086
+\ No newline at end of file
diff --git a/src/bank/CMakeLists.txt b/src/bank/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_library(bank bank_lib.c bank_api_account_withdrawal.c)
+target_link_libraries(bank PRIVATE
+ talerjson
+ talercurl
+ talerutil
+ talerbank
+ gnunetutil
+ gnunetcurl
+ gnunetjson
+ jansson
+ curl)
diff --git a/src/bank/bankAPI.c b/src/bank/bankAPI.c
@@ -0,0 +1,244 @@
+#include <string.h>
+#include <taler/taler_bank_service.h>
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+#include <stdio.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_bank_service_cash2ecash.h"
+
+
+
+static struct TALER_BANK_AuthenticationData auth;
+static struct GNUNET_CURL_Context *ctx;
+static struct GNUNET_CURL_RescheduleContext *rc;
+static struct TALER_BANK_AccountTokenHandle *ath;
+static struct TALER_BANK_AccountWithdrawalHandle *awh;
+static struct TALER_BANK_AccountWithdrawalConfirmHandle *awch;
+static const char *configfilename = "/home/manuel/.config/taler-exchange.conf";
+static const char *account_section = "bank-accountcredentials-cash2ecash";
+static const char *withdrawal_id;
+static const char *taler_withdraw_uri;
+struct TALER_Amount *testamount;
+struct TALER_Amount *testsuggestedamount;
+
+// Forward Declarations
+static void account_token_cb(void *cls,
+ const struct TALER_BANK_AccountTokenResponse *atr);
+static void account_withdrawal_cb(void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr);
+static void account_withdrawal_confirm_cb(
+ void *cls, const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr);
+
+
+
+
+
+/**
+ *Callback function for TALER_BANK_account_token
+ */
+static void account_token_cb(void *cls, const struct TALER_BANK_AccountTokenResponse *atr){
+ (void) cls;
+
+ ath = NULL;
+ switch (atr->http_status) {
+ case 0:
+ fprintf(stderr, "Failed to obtain HTTP reply from `%s'\n",
+ auth.wire_gateway_url);
+ break;
+ default:
+ fprintf (stderr,
+ "Failed to obtain debit history from `%s': HTTP status %u (%s)\n",
+ auth.wire_gateway_url,
+ atr->http_status,
+ TALER_ErrorCode_get_hint (atr->ec));
+ if (NULL != atr->response)
+ json_dumpf (atr->response,
+ stderr,
+ JSON_INDENT (2));
+ break;
+ }
+
+ //Switch Authentification method to Bearer and add Token
+ GNUNET_free(auth.details.basic.password);
+ GNUNET_free(auth.details.basic.username);
+ auth.method = TALER_BANK_AUTH_BEARER;
+ auth.details.bearer.token = GNUNET_strdup(atr->details.ok.access_token);
+
+ //Make Withdrawal request (Do I have to check if the account Token request did allready run completely?)
+
+ awh = TALER_BANK_account_withdrawal(ctx,
+ &auth,
+ "finsteraarhorn",
+ testamount,
+ testsuggestedamount,
+ &account_withdrawal_cb,
+ NULL);
+
+ if (NULL == awh){
+ printf("error with awh");
+ GNUNET_SCHEDULER_shutdown();
+ }
+
+ //GNUNET_SCHEDULER_shutdown();
+}
+
+
+
+/**
+ *Callback function for TALER_BANK_account_withdrawal
+ */
+static void account_withdrawal_cb(void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr){
+ (void) cls;
+ awh = NULL;
+
+ fprintf(stdout, "account withdrawal callback called\n");
+ fprintf(stdout, "%s\n", awr->details.ok.taler_withdraw_uri);
+ json_dumpf (awr->response,
+ stderr,
+ JSON_INDENT (2));
+
+ //Not sure if the correspondign memory is freed somewhere, might be neccessary to strdup and otherwise
+ //take responsibility to free.
+ withdrawal_id = awr->details.ok.withdrawal_id;
+ taler_withdraw_uri = awr->details.ok.taler_withdraw_uri;
+
+ char useserinput[5];
+ scanf("%s",useserinput);
+ if (0 != strcmp("go", useserinput)){
+ printf("error");
+ }
+
+ awch = TALER_BANK_account_withdrawal_confirm(ctx, &auth,
+ "finsteraarhorn",
+ withdrawal_id,
+ testsuggestedamount,
+ &account_withdrawal_confirm_cb,
+ NULL);
+ if (NULL == awch){
+ printf("error with awch");
+ GNUNET_SCHEDULER_shutdown();
+ }
+}
+
+/**
+ *Callback function for TALER_BANK_account_withdrawal_confirm
+ */
+static void account_withdrawal_confirm_cb(void *cls, const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr){
+ (void) cls;
+ awch = NULL;
+
+ fprintf(stderr, "%s", TALER_ErrorCode_get_hint (awcr->ec));
+ fprintf(stdout, "account withdrawal confirmation callback called\n");
+ GNUNET_SCHEDULER_shutdown();
+}
+
+/**
+ *Function to do the cleanup
+ */
+static void do_shutdown(void *cls){
+ (void) cls;
+
+ if(NULL != ath){
+ TALER_BANK_account_token_cancel(ath);
+ }
+
+ if (NULL != awh){
+ TALER_BANK_account_withdrawal_cancel(awh);
+ }
+
+ if (NULL != awch) {
+ TALER_BANK_account_withdrawal_confirm_cancel(awch);
+ }
+
+ if (NULL != ctx){
+ GNUNET_CURL_fini(ctx);
+ }
+
+ if (NULL != rc){
+ GNUNET_CURL_gnunet_rc_destroy(rc);
+ }
+ TALER_BANK_auth_free(&auth);
+}
+
+
+/**
+ *Main Program to be Run trough GNUNET_PROGRAM_run()
+ */
+static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg){
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ (void) cfg;
+
+ GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
+
+ ctx = GNUNET_CURL_init(&GNUNET_CURL_gnunet_scheduler_reschedule, &rc);
+ GNUNET_assert(NULL != ctx);
+ rc = GNUNET_CURL_gnunet_rc_create(ctx);
+
+
+ //Parse Config
+ if (GNUNET_OK != TALER_BANK_auth_parse_cfg(cfg, account_section, &auth)){
+ printf("error parsing authentification Data");
+ }
+
+ //Make Token request
+ struct GNUNET_TIME_Relative duration = {UINT64_MAX};
+ ath = TALER_BANK_account_token(ctx,
+ &auth,
+ "finsteraarhorn",
+ TALER_BANK_TOKEN_SCOPE_READWRITE,
+ true,
+ "this is a description",
+ duration,
+ &account_token_cb,
+ NULL);
+
+ if (NULL == ath){
+ printf("error with ath");
+ GNUNET_SCHEDULER_shutdown();
+ }
+
+ struct TALER_Amount amount;
+ TALER_string_to_amount("KUDOS:3.1415", &amount);
+ testamount = &amount;
+ testsuggestedamount = NULL;
+ printf("currency: %s\n",amount.currency);
+ printf("fraction: %d\n",amount.fraction);
+ printf("value: %ld\n",amount.value);
+
+
+
+}
+
+
+/**
+ *main runs function run() trough GNUNET_PROGRAM_run()
+ */
+int main(int argc,
+ char *const *argv){
+ int retval;
+
+ //Run Program
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ retval = GNUNET_PROGRAM_run(
+ TALER_EXCHANGE_project_data(),
+ argc, argv,
+ "bankapi-test",
+ gettext_noop("Test Function for bankapi"),
+ options,
+ &run, NULL);
+ if (GNUNET_SYSERR == retval)
+ return 3;
+ if (GNUNET_NO == retval)
+ return 0;
+
+ return 0;
+}
+
+
diff --git a/src/bank/bankCommunication.cpp b/src/bank/bankCommunication.cpp
@@ -0,0 +1 @@
+#include "bankCommunication.hpp"
diff --git a/src/bank/bankCommunication.hpp b/src/bank/bankCommunication.hpp
@@ -0,0 +1,4 @@
+#ifndef BANK_COMMUNICATION_H
+#define BANK_COMMUNICATION_H
+
+#endif
diff --git a/src/bank/bank_api_account_withdrawal.c b/src/bank/bank_api_account_withdrawal.c
@@ -0,0 +1,452 @@
+#include <curl/curl.h>
+#include <gnunet/gnunet_common.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <stdio.h>
+#include <taler/platform.h>
+#include "taler_bank_service_cash2ecash.h"
+#include <taler/taler_curl_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <taler/taler_json_lib.h>
+#include "bank_api_common.h"
+
+
+
+
+
+struct TALER_BANK_AccountWithdrawalHandle
+{
+ /**
+ *The url for this request.
+ */
+ char *request_url;
+
+ /**
+ POST context.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_BANK_AccountWithdrawalCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+};
+
+
+
+
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /account/$ACC/withdrawals request.
+ *
+ * @param cls the `struct TALER_BANK_AccountWithdrawalHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_account_withdrawal_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_BANK_AccountWithdrawalHandle *aai = cls;
+ const json_t *j = response;
+ struct TALER_BANK_AccountWithdrawalResponse ir = {
+ .http_status = response_code,
+ .response = response
+ };
+
+ aai->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("withdrawal_id",
+ &ir.details.ok.withdrawal_id),
+ GNUNET_JSON_spec_string ("taler_withdraw_uri",
+ &ir.details.ok.taler_withdraw_uri),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ ir.http_status = 0;
+ ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ }
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the bank is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break_op (0);
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ /* Access denied */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* Nothing really to verify, bank says invalid or missing credentials; we should
+ pass the JSON reply to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, maybe account really does not exist.
+ We should pass the JSON reply to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* The account does not have sufficient funds */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u\n",
+ (unsigned int) response_code);
+ GNUNET_break (0);
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ }
+ aai->cb (aai->cb_cls,
+ &ir);
+ TALER_BANK_account_withdrawal_cancel (aai);
+}
+
+
+
+
+struct TALER_BANK_AccountWithdrawalHandle *
+TALER_BANK_account_withdrawal (
+ struct GNUNET_CURL_Context *ctx,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *account_name,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *suggested_amount,
+ TALER_BANK_AccountWithdrawalCallback res_cb,
+ void *res_cb_cls)
+{
+ struct TALER_BANK_AccountWithdrawalHandle *awh;
+ json_t *withdrawal_req;
+ CURL *eh;
+
+ withdrawal_req = GNUNET_JSON_PACK(
+ GNUNET_JSON_pack_allow_null(
+ TALER_JSON_pack_amount("amount",
+ amount)),
+ GNUNET_JSON_pack_allow_null (
+ TALER_JSON_pack_amount("suggested_amount",
+ suggested_amount)));
+ if (NULL == withdrawal_req)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ awh = GNUNET_new (struct TALER_BANK_AccountWithdrawalHandle);
+ awh->cb = res_cb;
+ awh->cb_cls = res_cb_cls;
+ {
+ char *path;
+
+ GNUNET_asprintf (&path,
+ "accounts/%s/withdrawals",
+ account_name);
+ awh->request_url = TALER_url_join (auth->wire_gateway_url,
+ path,
+ NULL);
+ GNUNET_free (path);
+ }
+ if (NULL == awh->request_url)
+ {
+ GNUNET_free (awh);
+ json_decref (withdrawal_req);
+ return NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Posting withdrawal request at `%s'\n",
+ awh->request_url);
+ awh->post_ctx.headers
+ = curl_slist_append (
+ awh->post_ctx.headers,
+ "Content-Type: application/json");
+
+ eh = curl_easy_init ();
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_BANK_setup_auth_ (eh,
+ auth)) ||
+ (CURLE_OK !=
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ awh->request_url)) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&awh->post_ctx,
+ eh,
+ withdrawal_req)) )
+ {
+ GNUNET_break (0);
+ TALER_BANK_account_withdrawal_cancel (awh);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (withdrawal_req);
+ return NULL;
+ }
+ json_decref (withdrawal_req);
+ awh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ awh->post_ctx.headers,
+ &handle_account_withdrawal_finished,
+ awh);
+ GNUNET_assert (NULL != awh->job);
+ return awh;
+}
+
+void
+TALER_BANK_account_withdrawal_cancel (
+ struct TALER_BANK_AccountWithdrawalHandle *awh)
+{
+ if (NULL != awh->job)
+ {
+ GNUNET_CURL_job_cancel (awh->job);
+ awh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&awh->post_ctx);
+ GNUNET_free (awh->request_url);
+ GNUNET_free (awh);
+}
+
+
+
+
+/* ********************* /accounts/$ACC/withdrawals/$WITHDRAWAL_ID/confirm *********************** */
+
+
+
+
+struct TALER_BANK_AccountWithdrawalConfirmHandle
+{
+ /**
+ *The url for this request.
+ */
+ char *request_url;
+
+ /**
+ POST context.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_BANK_AccountWithdrawalConfirmCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+};
+
+/**
+ * Function called when we're done processing the
+ * HTTP /account/$ACC/withdrawals/$WITHDRAWAL_ID/confirm request.
+ *
+ * @param cls the `struct TALER_BANK_AccountWithdrawalConfirmHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_account_withdrawal_confirm_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_BANK_AccountWithdrawalConfirmHandle *aai = cls;
+ const json_t *j = response;
+ struct TALER_BANK_AccountWithdrawalConfirmResponse ir = {
+ .http_status = response_code,
+ .response = response
+ };
+
+ aai->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_ACCEPTED:
+ fprintf(stderr, "There is no implementation for 2FA yet");
+ ir.ec =TALER_JSON_get_error_code(j);
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the bank is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break_op (0);
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ /* Access denied */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* Nothing really to verify, bank says invalid or missing credentials; we should
+ pass the JSON reply to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, maybe account really does not exist.
+ We should pass the JSON reply to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* The account does not have sufficient funds */
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u\n",
+ (unsigned int) response_code);
+ GNUNET_break (0);
+ ir.ec = TALER_JSON_get_error_code (j);
+ break;
+ }
+ aai->cb (aai->cb_cls,
+ &ir);
+ TALER_BANK_account_withdrawal_confirm_cancel (aai);
+}
+
+
+
+
+struct TALER_BANK_AccountWithdrawalConfirmHandle *
+TALER_BANK_account_withdrawal_confirm (
+ struct GNUNET_CURL_Context *ctx,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *account_name,
+ const char *withdrawal_id,
+ const struct TALER_Amount *amount,
+ TALER_BANK_AccountWithdrawalConfirmCallback res_cb,
+ void *res_cb_cls)
+{
+ struct TALER_BANK_AccountWithdrawalConfirmHandle *awch;
+ json_t *wconfirm_req;
+ CURL *eh;
+
+ wconfirm_req = GNUNET_JSON_PACK(
+ GNUNET_JSON_pack_allow_null(
+ TALER_JSON_pack_amount("amount",
+ amount)));
+ if (NULL == wconfirm_req)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ awch = GNUNET_new (struct TALER_BANK_AccountWithdrawalConfirmHandle);
+ awch->cb = res_cb;
+ awch->cb_cls = res_cb_cls;
+ {
+ char *path;
+
+ GNUNET_asprintf (&path,
+ "accounts/%s/withdrawals/%s/confirm",
+ account_name, withdrawal_id);
+ awch->request_url = TALER_url_join (auth->wire_gateway_url,
+ path,
+ NULL);
+ GNUNET_free (path);
+ }
+ if (NULL == awch->request_url)
+ {
+ GNUNET_free (awch);
+ json_decref (wconfirm_req);
+ return NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Posting withdrawal confirmation request at `%s'\n",
+ awch->request_url);
+ awch->post_ctx.headers
+ = curl_slist_append (
+ awch->post_ctx.headers,
+ "Content-Type: application/json");
+
+ eh = curl_easy_init ();
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_BANK_setup_auth_ (eh,
+ auth)) ||
+ (CURLE_OK !=
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ awch->request_url)) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&awch->post_ctx,
+ eh,
+ wconfirm_req)) )
+ {
+ GNUNET_break (0);
+ TALER_BANK_account_withdrawal_confirm_cancel (awch);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (wconfirm_req);
+ return NULL;
+ }
+ json_decref (wconfirm_req);
+ awch->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ awch->post_ctx.headers,
+ &handle_account_withdrawal_confirm_finished,
+ awch);
+ GNUNET_assert (NULL != awch->job);
+ return awch;
+}
+
+void
+TALER_BANK_account_withdrawal_confirm_cancel (
+ struct TALER_BANK_AccountWithdrawalConfirmHandle *awch)
+{
+ if (NULL != awch->job)
+ {
+ GNUNET_CURL_job_cancel (awch->job);
+ awch->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&awch->post_ctx);
+ GNUNET_free (awch->request_url);
+ GNUNET_free (awch);
+}
+
diff --git a/src/bank/bank_api_common.h b/src/bank/bank_api_common.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2015, 2016, 2017 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/>
+*/
+/**
+ * @file bank-lib/bank_api_common.h
+ * @brief Common functions for the bank API
+ * @author Christian Grothoff
+ */
+#ifndef BANK_API_COMMON_H
+#define BANK_API_COMMON_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_bank_service.h>
+#include <taler/taler_json_lib.h>
+
+
+/**
+ * Set authentication data in @a easy from @a auth.
+ *
+ * @param easy curl handle to setup for authentication
+ * @param auth authentication data to use
+ * @return #GNUNET_OK in success
+ */
+enum GNUNET_GenericReturnValue
+TALER_BANK_setup_auth_ (CURL *easy,
+ const struct TALER_BANK_AuthenticationData *auth);
+
+
+#endif
diff --git a/src/bank/bank_lib.c b/src/bank/bank_lib.c
@@ -0,0 +1,195 @@
+#include <string.h>
+#include <taler/taler_bank_service.h>
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+#include <stdio.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_bank_service_cash2ecash.h"
+#include "bank_lib.h"
+
+
+static struct TALER_BANK_AuthenticationData auth;
+static const char *account_section = "bank-accountcredentials-cash2ecash";
+
+static struct GNUNET_CURL_Context *ctx;
+static struct GNUNET_CURL_RescheduleContext *rc;
+static struct TALER_BANK_AccountTokenHandle *ath;
+static struct TALER_BANK_AccountWithdrawalHandle *awh;
+static struct TALER_BANK_AccountWithdrawalConfirmHandle *awch;
+// static const char *configfilename =
+// "/home/manuel/.config/taler-exchange.conf"; static const char *withdrawal_id;
+// static const char *taler_withdraw_uri;
+
+/**
+ *Parameters of Withdrawal Request call.
+ */
+static bankCommunicationWithdrawalCallback_t extWithdrawalCallback;
+
+
+/**
+ *Function to do the cleanup
+ */
+static void do_shutdown(void *cls){
+ (void) cls;
+
+ if(NULL != ath){
+ TALER_BANK_account_token_cancel(ath);
+ }
+
+ if (NULL != awh){
+ TALER_BANK_account_withdrawal_cancel(awh);
+ }
+
+ if (NULL != awch) {
+ TALER_BANK_account_withdrawal_confirm_cancel(awch);
+ }
+
+ if (NULL != ctx){
+ GNUNET_CURL_fini(ctx);
+ }
+
+ if (NULL != rc){
+ GNUNET_CURL_gnunet_rc_destroy(rc);
+ }
+ TALER_BANK_auth_free(&auth);
+}
+
+/**
+ *Callback function for TALER_BANK_account_withdrawal
+ */
+static void account_withdrawal_cb(void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr){
+ (void) cls;
+ awh = NULL;
+
+ fprintf(stdout, "account withdrawal callback called\n");
+ fprintf(stdout, "%s\n", awr->details.ok.taler_withdraw_uri);
+ json_dumpf (awr->response,
+ stderr,
+ JSON_INDENT (2));
+
+ //Call callback with results.
+ extWithdrawalCallback(awr->details.ok.withdrawal_id, awr->details.ok.taler_withdraw_uri);
+}
+
+
+
+/**
+ *Callback function for TALER_BANK_account_token
+ */
+static void account_token_cb(void *cls, const struct TALER_BANK_AccountTokenResponse *atr){
+ (void) cls;
+
+ ath = NULL;
+ switch (atr->http_status) {
+ case 0:
+ fprintf(stderr, "Failed to obtain HTTP reply from `%s'\n",
+ auth.wire_gateway_url);
+ break;
+ default:
+ fprintf (stderr,
+ "Failed to obtain debit history from `%s': HTTP status %u (%s)\n",
+ auth.wire_gateway_url,
+ atr->http_status,
+ TALER_ErrorCode_get_hint (atr->ec));
+ if (NULL != atr->response)
+ json_dumpf (atr->response,
+ stderr,
+ JSON_INDENT (2));
+ break;
+ }
+
+ //Switch Authentification method to Bearer and add Token
+ GNUNET_free(auth.details.basic.password);
+ GNUNET_free(auth.details.basic.username);
+ auth.method = TALER_BANK_AUTH_BEARER;
+ auth.details.bearer.token = GNUNET_strdup(atr->details.ok.access_token);
+
+ printf("fertig in bankcomu\n");
+}
+
+static void runStartup(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg){
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ (void) cfg;
+
+ //Shutdown for the GNUNET scheduler
+ GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
+
+ //Initialize Curl
+ ctx = GNUNET_CURL_init(&GNUNET_CURL_gnunet_scheduler_reschedule, &rc);
+ GNUNET_assert(NULL != ctx);
+ rc = GNUNET_CURL_gnunet_rc_create(ctx);
+
+ //Parse config to obtain authentification data
+ if (GNUNET_OK != TALER_BANK_auth_parse_cfg(cfg, account_section, &auth)){
+ printf("error parsing authentification Data");
+ }
+
+ //Request an access Token
+ //Make Token request
+ struct GNUNET_TIME_Relative duration = {UINT64_MAX};
+ ath = TALER_BANK_account_token(ctx,
+ &auth,
+ "finsteraarhorn",
+ TALER_BANK_TOKEN_SCOPE_READWRITE,
+ true,
+ "this is a description",
+ duration,
+ &account_token_cb,
+ NULL);
+
+}
+
+
+int bankCommunicationInit(){
+ int argc = 0;
+ char *const *argv = NULL;
+ int retval;
+
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ retval = GNUNET_PROGRAM_run(
+ TALER_EXCHANGE_project_data(),
+ argc, argv,
+ "cash2ecash",
+ gettext_noop("cash2ecash bank communication library"),
+ options,
+ &runStartup, NULL);
+ if (GNUNET_SYSERR == retval)
+ return 3;
+ if (GNUNET_NO == retval)
+ return 0;
+
+ return 0;
+}
+
+
+
+int bankCommunicationWithdrawalRequest(struct TALER_Amount amount, struct TALER_Amount suggestedAmount, bankCommunicationWithdrawalCallback_t callback){
+ //Store the function callback globally
+ extWithdrawalCallback = callback;
+
+ //Make Withdrawal request (Do I have to check if the account Token request did allready run completely?)
+ awh = TALER_BANK_account_withdrawal(ctx,
+ &auth,
+ "finsteraarhorn",
+ &amount,
+ &suggestedAmount,
+ &account_withdrawal_cb,
+ NULL);
+
+ if (NULL == awh){
+ printf("error with awh");
+ GNUNET_SCHEDULER_shutdown();
+ }
+
+ //GNUNET_SCHEDULER_shutdown();
+
+ return 0;
+}
+
diff --git a/src/bank/bank_lib.h b/src/bank/bank_lib.h
@@ -0,0 +1,24 @@
+#ifndef BANK_LIB_H
+#define BANK_LIB_H
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+typedef void (*bankCommunicationWithdrawalCallback_t)(const char *withdrawal_id, const char *taler_withdraw_uri);
+//typedef void (*bankCommunicationCallback_t)();
+//typedef void (*bankCommunicationCallback_t)();
+
+
+int bankCommunicationInit();
+int bankCommunicationWithdrawalRequest(struct TALER_Amount amount, struct TALER_Amount suggestedAmount, bankCommunicationWithdrawalCallback_t callback);
+
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+#endif
diff --git a/src/bank/taler_bank_service_cash2ecash.h b/src/bank/taler_bank_service_cash2ecash.h
@@ -0,0 +1,200 @@
+#include <jansson.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_util.h>
+#include <taler/taler_error_codes.h>
+
+#include <taler/taler_bank_service.h>
+
+
+
+/* ********************* /accounts/$ACC/withdrawals *********************** */
+
+
+/**
+ * @brief A /accounts/$USERNAME/withdrawals request handle
+ */
+struct TALER_BANK_AccountWithdrawalHandle;
+
+
+/**
+ * Response details for a withdrawal request.
+ */
+struct TALER_BANK_AccountWithdrawalResponse
+{
+
+ /**
+ * HTTP status.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+ /**
+ * Details returned depending on the @e http_status.
+ */
+ union
+ {
+
+ /**
+ * Details if status was #MHD_HTTP_OK
+ */
+ struct
+ {
+ /**
+ * Withdrawal ID
+ */
+ const char *withdrawal_id;
+
+ /**
+ * Taler Withdraw URI
+ */
+ const char *taler_withdraw_uri;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to return the result of submitting
+ * a request for an withdrawal to the bank.
+ *
+ * @param cls closure
+ * @param awr response details
+ */
+typedef void
+(*TALER_BANK_AccountWithdrawalCallback) (
+ void *cls,
+ const struct TALER_BANK_AccountWithdrawalResponse *awr);
+
+
+
+
+/**
+ * Posts a withdrawal request to the bank
+ *
+ * @param ctx curl context for the event loop
+ * @param auth authentication data to send to the bank
+ * @param account_name username of the bank account to which the withdrawal request is sent.
+ * @param amount amount to withdraw (not mandatory, NULL if unspecified)
+ * #param suggested_amount suggesiton for the amount, which can be changed by the wallet. (NULL if unspecified)
+ * @param res_cb the callback to call when the final result for this request is available
+ * @param res_cb_cls closure for the above callback
+ * @return NULL
+ * if the inputs are invalid (i.e. invalid amount) or internal errors.
+ * In this case, the callback is not called.
+ */
+struct TALER_BANK_AccountWithdrawalHandle *
+TALER_BANK_account_withdrawal (
+ struct GNUNET_CURL_Context *ctx,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *account_name,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *suggested_amount,
+ TALER_BANK_AccountWithdrawalCallback res_cb,
+ void *res_cb_cls);
+
+
+/**
+ * Cancel an account withdrawal operation. This function cannot be used on a
+ * request handle if a response is already served for it.
+ *
+ * @param[in] awh the withdrawal request handle
+ */
+void
+TALER_BANK_account_withdrawal_cancel (
+ struct TALER_BANK_AccountWithdrawalHandle *awh);
+
+
+/* ********************* /accounts/$ACC/withdrawals/$WITHDRAWAL_ID/confirm *********************** */
+
+/**
+ * @brief A /accounts/$USERNAME/withdrawals/$WITHDRAWAL_ID/confirm request handle
+ */
+struct TALER_BANK_AccountWithdrawalConfirmHandle;
+
+
+/**
+ * Response details for a withdrawal confirmation request.
+ */
+struct TALER_BANK_AccountWithdrawalConfirmResponse
+{
+
+ /**
+ * HTTP status.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+};
+
+
+/**
+ * Callbacks of this type are used to return the result of submitting
+ * a request for an withdrawal confirmation to the bank.
+ *
+ * @param cls closure
+ * @param awr response details
+ */
+typedef void
+(*TALER_BANK_AccountWithdrawalConfirmCallback) (
+ void *cls,
+ const struct TALER_BANK_AccountWithdrawalConfirmResponse *awcr);
+
+
+
+
+/**
+ * Posts a withdrawal confirmation request to the bank
+ *
+ * @param ctx curl context for the event loop
+ * @param auth authentication data to send to the bank
+ * @param account_name username of the bank account to which the withdrawal request is sent.
+ * #param withdrawal_id id of the withdrawal to confirm
+ * @param amount amount to withdraw (not mandatory, NULL if unspecified)
+ * @param res_cb the callback to call when the final result for this request is available
+ * @param res_cb_cls closure for the above callback
+ * @return NULL
+ * if the inputs are invalid (i.e. invalid amount) or internal errors.
+ * In this case, the callback is not called.
+ */
+struct TALER_BANK_AccountWithdrawalConfirmHandle *
+TALER_BANK_account_withdrawal_confirm (
+ struct GNUNET_CURL_Context *ctx,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *account_name,
+ const char *withdrawal_id,
+ const struct TALER_Amount *amount,
+ TALER_BANK_AccountWithdrawalConfirmCallback res_cb,
+ void *res_cb_cls);
+
+
+/**
+ * Cancel an account withdrawal confirm operation. This function cannot be used on a
+ * request handle if a response is already served for it.
+ *
+ * @param[in] awch the withdrawal confirm request handle
+ */
+void
+TALER_BANK_account_withdrawal_confirm_cancel (
+ struct TALER_BANK_AccountWithdrawalConfirmHandle *awch);
+
diff --git a/src/cash2ecash.cpp b/src/cash2ecash.cpp
@@ -4,6 +4,7 @@
#include <ostream>
#include <src/misc/lv_types.h>
#include <vector>
+#include "bank/bank_lib.h"
#include "cashacceptors.hpp"
#include "gui/screen.hpp"
#include "gui/screenAcceptCash.hpp"
@@ -13,7 +14,7 @@
#include "utils.hpp"
#include "gui.hpp"
#include "global.hpp"
-
+#include "bank.hpp"
// Global Definitions
enum state_e {
@@ -30,7 +31,8 @@ enum state_e {
enum state_e state = INIT;
-char test;
+
+
char hello[] = "hello";
char world[] = "wold";
char *string = hello;
@@ -55,6 +57,13 @@ stateEventPair stateEventTable[NUMBER_OF_STATES][NUMBER_OF_EVENTS];
void actionEventInitialize() {
std::cout << "Event action initialze called" << std::endl;
+ //testing
+ bankCommunicationInit();
+ std::cout << "fertig in Main" << std::endl;
+
+
+
+ //end testing
gui.setActiveScreen(screenWelcome);
}
@@ -64,7 +73,8 @@ void actionEventUnexpected(){
void actionEventStart(){
std::cout << "Action Event Start called" << std::endl;
- gui.setActiveScreen(screenIdentification);
+ //gui.setActiveScreen(screenIdentification);
+ gui.setActiveScreen(screenConnection);
}
void actionEventAbortIdent(){
@@ -151,7 +161,7 @@ void initStateEvent(){
stateEventTable[INIT][EVENT_INITIALIZE].action = actionEventInitialize;
stateEventTable[INIT][EVENT_INITIALIZE].nextState = IDLE;
stateEventTable[IDLE][EVENT_BUTTON_START].action = actionEventStart;
- stateEventTable[IDLE][EVENT_BUTTON_START].nextState = IDENTIFICATION;
+ stateEventTable[IDLE][EVENT_BUTTON_START].nextState = CONNECTION; //needs to be changed to initialization later
stateEventTable[IDLE][EVENT_SLEEP].action = actionEventSleep;
stateEventTable[IDLE][EVENT_SLEEP].nextState = SLEEP;
@@ -205,9 +215,6 @@ int main(int argc, char *argv[]){
//Trigger Initialzation Event
eventHandler(EVENT_INITIALIZE);
-
-
-
while (true) {
guiDriver();
diff --git a/src/include/bank.hpp b/src/include/bank.hpp
@@ -0,0 +1,6 @@
+#ifndef BANK_H
+#define BANK_H
+
+#include "../bank/bank_lib.h"
+
+#endif