gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cash2ecash] branch master updated: draft of bank communication ready fo


From: gnunet
Subject: [cash2ecash] branch master updated: draft of bank communication ready for testing
Date: Wed, 01 Jan 2025 20:52:03 +0100

This is an automated email from the git hooks/post-receive script.

manuel-geissbuehler pushed a commit to branch master
in repository cash2ecash.

The following commit(s) were added to refs/heads/master by this push:
     new 0fa8927  draft of bank communication ready for testing
0fa8927 is described below

commit 0fa8927937997f9b836b3ea0902ab14bee65b795
Author: Manuel Geissbühler <manuel@debian>
AuthorDate: Wed Jan 1 20:51:50 2025 +0100

    draft of bank communication ready for testing
---
 src/bank/bankCommunication.hpp | 50 ++++++++++++++++++++++++++--
 src/bank/bank_lib.c            | 75 +++++++++++++++++++++++++++++++++---------
 src/bank/bank_lib.h            | 15 ++++++---
 src/cash2ecash.cpp             | 35 +++++++++++---------
 src/gui/screenConnection.hpp   |  2 +-
 src/include/bank.hpp           |  2 +-
 src/include/global.hpp         |  2 +-
 7 files changed, 140 insertions(+), 41 deletions(-)

diff --git a/src/bank/bankCommunication.hpp b/src/bank/bankCommunication.hpp
index 9e65d35..a21b8f4 100644
--- a/src/bank/bankCommunication.hpp
+++ b/src/bank/bankCommunication.hpp
@@ -1,14 +1,60 @@
 #ifndef BANK_COMMUNICATION_H
 #define BANK_COMMUNICATION_H
 
-#include "taler_bank_service_cash2ecash.h"
+#include "bank_lib.h"
+#include "global.hpp"
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <ostream>
 
 class BankCommunication{
   private:
+
+  static const char **status;
+
+  static void initCallback(){
+    eventHandler(EVENT_BANK_TOKEN_DONE);
+  }
+  
+  static void withdrawalRequestCallback(){
+    eventHandler(EVENT_BANK_WITHDRAWAL_DONE);
+  }
+
+  static void withdrawalConfirmRequestCallback(){
+    eventHandler(EVENT_BANK_W_CONFIRMATION_DONE);
+  }
+
+  static void withdrawalIDInfoRequestCallback(){
+    if  (0 == strcmp(*status, "pending")){
+      eventHandler(EVENT_BANK_W_STATUS_PENDING);
+    }else if (0 == strcmp(*status, "selected")) {
+      eventHandler(EVENT_BANK_W_STATUS_SELECTED);
+    }else if (0 == strcmp(*status, "aborted")) {
+      eventHandler(EVENT_BUTTON_ABORT);
+    }else{
+      std::cerr << "Unexpected Withdrawal Staus: " << *status << std::endl;
+      exit(EXIT_FAILURE);
+    }
+  }
+  
   protected:
   public:
-  
+    void init(){
+    bankCommunicationInit(initCallback);
+  }
+
+  void withdrawalRequest(struct TALER_Amount *amount, struct TALER_Amount 
*suggestedAmount, const char **res_withdrawal_id, const char 
**res_taler_withdraw_uri){
+    bankCommunicationWithdrawalRequest(amount, suggestedAmount, 
res_withdrawal_id, res_taler_withdraw_uri, withdrawalRequestCallback);
+  }
+
+  void withdrawalConfirmReques(const char *withdrawal_id, struct TALER_Amount 
*amount){
+    bankCommunicationWithdrawalConfirmRequest(withdrawal_id, amount, 
withdrawalConfirmRequestCallback);
+  }
 
+  void withrawalStatusRequest(const char *withdrawal_id){
+    bankCommunicationWithdrawalIDInfoRequest(withdrawal_id, status, 
withdrawalIDInfoRequestCallback);
+  }
 };
 
 #endif
diff --git a/src/bank/bank_lib.c b/src/bank/bank_lib.c
index 8cefb01..9eaad0f 100644
--- a/src/bank/bank_lib.c
+++ b/src/bank/bank_lib.c
@@ -1,4 +1,3 @@
-#include <string.h>
 #include <taler/taler_bank_service.h>
 #include <taler/taler_util.h>
 #include <gnunet/gnunet_common.h>
@@ -7,6 +6,9 @@
 #include <gnunet/gnunet_curl_lib.h>
 #include <gnunet/gnunet_util_lib.h>
 #include "taler_bank_service_cash2ecash.h"
+
+
+
 #include "bank_lib.h"
 
 char *programname = "cash2ecash";
@@ -24,25 +26,32 @@ static struct TALER_BANK_WithdrawalIDInfoHandle *awih;
 // "/home/manuel/.config/taler-exchange.conf"; static const char 
*withdrawal_id;
 // static const char *taler_withdraw_uri;
 
+/**
+ *Parameters of Init (Token Request) call.
+ */
+static bankCommunicationInitCallback_t extInitCallback;
+
 /**
  *Parameters of Withdrawal Request call.
  */
 static bankCommunicationWithdrawalCallback_t extWithdrawalCallback;
-static struct TALER_Amount parAmount, parSuggestedAmount;
+static struct TALER_Amount *parAmount, *parSuggestedAmount;
+const char **par_res_withdrawal_id, **par_res_taler_withdraw_uri;
 
 
 /**
  *Parameters of Withdrawal Confirm Request call.
  */
-static bankCommunicationWithdrawalConfirmatCallback_t 
extWithdrawalConfirmCallback;
-static char *parWithdrawal_id;
-static struct TALER_Amount parConfirmAmount;
+static bankCommunicationWithdrawalConfirmCallback_t 
extWithdrawalConfirmCallback;
+static const char *parWithdrawal_id;
+static struct TALER_Amount *parConfirmAmount;
 
 /**
  *Parameters of Withdrawal ID info Request call.
  */
 static bankCommunicationWithdrawalIDInfoCallback_t extWithdrawalIDInfoCallback;
-static char *parInfoWithdrawal_id;
+static const char *parInfoWithdrawal_id;
+const char **par_res_status;
 
 /**
  *Function to do the cleanup
@@ -62,6 +71,10 @@ static void do_shutdown(void *cls){
     TALER_BANK_account_withdrawal_confirm_cancel(awch);
   }
 
+  if (NULL != awih) {
+    TALER_BANK_withdrawalID_info_cancel(awih);
+  }
+
   if (NULL != ctx){
     GNUNET_CURL_fini(ctx);
   }
@@ -86,8 +99,10 @@ static void account_withdrawal_cb(void *cls,
                   stderr,
                   JSON_INDENT (2));
 
-  //Call callback with results.  
-  extWithdrawalCallback(awr->details.ok.withdrawal_id, 
awr->details.ok.taler_withdraw_uri);
+  //Assign pointer to results and call callback
+  *par_res_withdrawal_id = awr->details.ok.withdrawal_id; //maybe need to 
strdup?
+  *par_res_taler_withdraw_uri = awr->details.ok.taler_withdraw_uri; //maybe 
need to strdup?
+  extWithdrawalCallback();
 }
 
 
@@ -115,6 +130,8 @@ static void account_token_cb(void *cls, const struct 
TALER_BANK_AccountTokenResp
                   stderr,
                   JSON_INDENT (2));
     break;
+
+    extInitCallback();
   }
 
   //Switch Authentification method to Bearer and add Token
@@ -184,7 +201,8 @@ static void withdrawalID_info_cb(void *cls, const struct 
TALER_BANK_WithdrawalID
     break;
   }
 
-  //Call callback with the results
+   //Assign pointer to results and call callback
+  *par_res_status = widr->details.ok.status; //maybe need to strdup?
   extWithdrawalIDInfoCallback();
 
   GNUNET_SCHEDULER_shutdown();
@@ -239,7 +257,6 @@ static void runToken(void *cls, char *const *args, const 
char *cfgfile, const st
 
   bankCommunicationRunInit(cfg);
 
-  //Request an access Token
   //Make Token request
   struct GNUNET_TIME_Relative duration = {UINT64_MAX};
   ath = TALER_BANK_account_token(ctx,
@@ -270,8 +287,8 @@ static void runWithdrawalRequest(void *cls, char *const 
*args, const char *cfgfi
   awh = TALER_BANK_account_withdrawal(ctx,
                                      &auth,
                                      "finsteraarhorn",
-                                     &parAmount,
-                                     &parSuggestedAmount,
+                                     parAmount,
+                                     parSuggestedAmount,
                                      account_withdrawal_cb,
                                      NULL);
 
@@ -295,7 +312,7 @@ static void runWithdrawalConfirmRequest(void *cls, char 
*const *args, const char
                                               &auth,
                                               "finsteraarhorn",
                                               parWithdrawal_id,
-                                              &parConfirmAmount,
+                                              parConfirmAmount,
                                               account_withdrawal_confirm_cb,
                                               NULL);
 
@@ -332,16 +349,42 @@ static void runWithdrawalIDInfoRequest(void *cls, char 
*const *args, const char
  *Interface functions
  */
 
-void bankCommunicationInit() { bankCommunicationRun(runToken); }
-
+void bankCommunicationInit(bankCommunicationInitCallback_t callback) {
+  extInitCallback = callback;
+  bankCommunicationRun(runToken);
+}
 
-void bankCommunicationWithdrawalRequest(struct TALER_Amount amount, struct 
TALER_Amount suggestedAmount, bankCommunicationWithdrawalCallback_t callback){
+void bankCommunicationWithdrawalRequest(struct TALER_Amount *amount, struct 
TALER_Amount *suggestedAmount, const char **res_withdrawal_id, const char 
**res_taler_withdraw_uri, bankCommunicationWithdrawalCallback_t callback){
   //Store the parameters globaly
   extWithdrawalCallback = callback;
   parAmount = amount;
   parSuggestedAmount = suggestedAmount;
+  par_res_withdrawal_id = res_withdrawal_id;
+  par_res_taler_withdraw_uri = res_taler_withdraw_uri;
+
   
   //Run request trough gnunet program run
   bankCommunicationRun(runWithdrawalRequest);
 }
 
+void bankCommunicationWithdrawalIDInfoRequest(const char *withdrawal_id, const 
char **res_status, bankCommunicationWithdrawalIDInfoCallback_t callback){
+  //Store the parameters globaly
+  extWithdrawalIDInfoCallback = callback;
+  parInfoWithdrawal_id = withdrawal_id;
+  par_res_status = res_status;
+  
+  //Run request trough gnunet program run
+  bankCommunicationRun(runWithdrawalIDInfoRequest);  
+}
+
+void bankCommunicatonWithdrawalConfirmRequest(const char *withdrawal_id, 
struct TALER_Amount *amount, bankCommunicationWithdrawalConfirmCallback_t 
callback){
+  //Store the parameters globaly
+  extWithdrawalConfirmCallback = callback;
+  parWithdrawal_id = withdrawal_id;
+  parConfirmAmount = amount;
+  
+  //Run request trough gnunet program run
+  bankCommunicationRun(runWithdrawalConfirmRequest);
+}
+
+
diff --git a/src/bank/bank_lib.h b/src/bank/bank_lib.h
index 3bb7ca8..ce90e88 100644
--- a/src/bank/bank_lib.h
+++ b/src/bank/bank_lib.h
@@ -6,15 +6,20 @@ extern "C"
 #endif
 
 
+//Allow to directly include amount lib, might lead to other bugs..
+#define __TALER_UTIL_LIB_H_INSIDE__
+#include <taler/taler_amount_lib.h>
 
-
-typedef void (*bankCommunicationWithdrawalCallback_t)(const char 
*withdrawal_id, const char *taler_withdraw_uri);
-typedef void (*bankCommunicationWithdrawalConfirmatCallback_t)();
+typedef void (*bankCommunicationInitCallback_t)();  
+typedef void (*bankCommunicationWithdrawalCallback_t)();
+typedef void (*bankCommunicationWithdrawalConfirmCallback_t)();
 typedef void (*bankCommunicationWithdrawalIDInfoCallback_t)();
 
 
-void bankCommunicationInit();
-void bankCommunicationWithdrawalRequest(struct TALER_Amount amount, struct 
TALER_Amount suggestedAmount, bankCommunicationWithdrawalCallback_t callback);
+void bankCommunicationInit(bankCommunicationInitCallback_t callback);
+void bankCommunicationWithdrawalRequest(struct TALER_Amount *amount, struct 
TALER_Amount *suggestedAmount, const char **res_withdrawal_id, const char 
**res_taler_withdraw_uri, bankCommunicationWithdrawalCallback_t callback);
+void bankCommunicationWithdrawalIDInfoRequest(const char *withdrawal_id, const 
char **res_status, bankCommunicationWithdrawalIDInfoCallback_t callback);
+void bankCommunicationWithdrawalConfirmRequest(const char *withdrawal_id, 
struct TALER_Amount *amount, bankCommunicationWithdrawalConfirmCallback_t 
callback);
 
 
 
diff --git a/src/cash2ecash.cpp b/src/cash2ecash.cpp
index 32c5bd9..aeaf188 100644
--- a/src/cash2ecash.cpp
+++ b/src/cash2ecash.cpp
@@ -4,7 +4,7 @@
 #include <ostream>
 #include <src/misc/lv_types.h>
 #include <vector>
-#include "bank/bank_lib.h"
+#include "bank/bankCommunication.hpp"
 #include "cashacceptors.hpp"
 #include "gui/screen.hpp"
 #include "gui/screenAcceptCash.hpp"
@@ -31,18 +31,22 @@ enum state_e {
 
 enum state_e state = INIT;
 
+const char **withdrawal_id;
+const char **taler_withdraw_uri;
 
 
 char hello[] = "hello";
 char world[] = "wold";
 char *string = hello;
 Gui gui;
+Timer withdrawalStatusTimer;
 
 ScreenWelcome *screenWelcome = new ScreenWelcome;
 ScreenIdentification *screenIdentification = new ScreenIdentification;
 ScreenConnection  *screenConnection = new ScreenConnection;
 ScreenAcceptCash  *screenAcceptCash = new ScreenAcceptCash(string);
 void guiDriver();
+BankCommunication bankCommunication;
 
 typedef void(*action_t)();
 
@@ -57,13 +61,6 @@ 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);
 }
 
@@ -97,25 +94,32 @@ void actionEventSleep() { std::cout << "Action Event xx 
called" << std::endl; }
 void actionEventWakeup() { std::cout << "Action Event xx called" << std::endl; 
}
 
 void actionEventIdentificationSuccess(){
-  std::cout << "Action Event xx called" << std::endl;
+  std::cout << "Action Event Identification Success called" << std::endl;
   gui.setActiveScreen(screenConnection);
+  bankCommunication.init();
 }
 
 void actionEventBankTokenDone(){
   std::cout << "Action Event Bank Token called" << std::endl;
+  static struct TALER_Amount amountZero;
+  TALER_amount_set_zero("KUDOS", &amountZero);
+  bankCommunication.withdrawalRequest(NULL, &amountZero, withdrawal_id, 
taler_withdraw_uri);
 }
 
 void actionEventBankWithdrawalDone(){
-  std::cout << "Action Event Bank Withdrawal called" << std::endl;
+  std::cout << "Action Event Bank Withdrawal Done called" << std::endl;
+  screenConnection->generateQR(*taler_withdraw_uri);
+  bankCommunication.withrawalStatusRequest(*withdrawal_id);
 }
 
-void actionEventBankWStatusConfirmed(){
+void actionEventBankWStatusSelected(){
   std::cout << "Action Event Bank Withdrawal Status Confirmed called" << 
std::endl;
   gui.setActiveScreen(screenAcceptCash);
 }
 
 void actionEventBankWStatusPending(){
   std::cout << "Action Event Bank Withdrawal Status Pending called" << 
std::endl;
+  bankCommunication.withrawalStatusRequest(*withdrawal_id);
 }
 
 void actionEventWConfirmationDone(){
@@ -130,7 +134,9 @@ void actionEventIdentificationTimeout(){
 
 void actionEventAcceptCashTimeout(){
   std::cout << "Action Event Acceptcash Timeout called" << std::endl;
-  gui.setActiveScreen(screenWelcome);
+  static struct TALER_Amount confirmedAmount;
+  TALER_string_to_amount("KUDOS:2.0", &confirmedAmount);
+  bankCommunication.withdrawalConfirmReques(*withdrawal_id, &confirmedAmount);
 }
 
 void actionEventConnectionTimeout(){
@@ -183,8 +189,8 @@ void initStateEvent(){
   stateEventTable[CONNECTION][EVENT_BANK_WITHDRAWAL_DONE].nextState = 
CONNECTION;
   stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_PENDING].action = 
actionEventBankWStatusPending;
   stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_PENDING].nextState = 
CONNECTION;
-  stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_CONFIRMED].action = 
actionEventBankWStatusConfirmed;
-  stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_CONFIRMED].nextState = 
ACCEPTCASH;
+  stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_SELECTED].action = 
actionEventBankWStatusSelected;
+  stateEventTable[CONNECTION][EVENT_BANK_W_STATUS_SELECTED].nextState = 
ACCEPTCASH;
   stateEventTable[CONNECTION][EVENT_TIMEOUT].action = 
actionEventConnectionTimeout;
   stateEventTable[CONNECTION][EVENT_TIMEOUT].nextState = IDLE;
   
@@ -205,7 +211,6 @@ void eventHandler(event_e event){
 int main(int argc, char *argv[]){
   char serialpath[] = "/dev/ttyAMA3";
   std::cout << "The Program is running" <<std::endl;
-  //DG600F cashacceptor(serialpath);
   Timer timer1;
   timer1.setTimeMillis(10000);
   TALER_Amount testamount;
diff --git a/src/gui/screenConnection.hpp b/src/gui/screenConnection.hpp
index b2c0150..4eba507 100644
--- a/src/gui/screenConnection.hpp
+++ b/src/gui/screenConnection.hpp
@@ -39,7 +39,7 @@ class ScreenConnection : public Screen{
     lv_qrcode_set_light_color(qrCode, lv_color_white());
   }
 
-  void generateQR(char* uri){
+  void generateQR(const char* uri){
     lv_qrcode_update(qrCode, uri, strlen(uri));
     lv_obj_center(qrCode);
   }
diff --git a/src/include/bank.hpp b/src/include/bank.hpp
index ccdce4a..0c07de8 100644
--- a/src/include/bank.hpp
+++ b/src/include/bank.hpp
@@ -1,6 +1,6 @@
 #ifndef BANK_H
 #define BANK_H
 
-#include "../bank/bank_lib.h"
+#include "../bank/bankCommunication.hpp"
 
 #endif
diff --git a/src/include/global.hpp b/src/include/global.hpp
index c228dec..2f60f02 100644
--- a/src/include/global.hpp
+++ b/src/include/global.hpp
@@ -12,7 +12,7 @@ enum event_e {
   EVENT_IDENTIFICATION_SUCCESS,
   EVENT_BANK_TOKEN_DONE,
   EVENT_BANK_WITHDRAWAL_DONE,
-  EVENT_BANK_W_STATUS_CONFIRMED,
+  EVENT_BANK_W_STATUS_SELECTED,
   EVENT_BANK_W_STATUS_PENDING,
   EVENT_BANK_W_CONFIRMATION_DONE,
   ENUM_EVENT_END

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]