cash2ecash

cash2ecash: cash acceptor that issues digital cash (experimental)
Log | Files | Refs | README | LICENSE

commit 71ab1b2a002e3bbdde5a606f761cae12f6d592af
parent be3f1df99af1106c212e3f4548b3c178e1be34d4
Author: Tellenbach Reto <tellr1@bfh.ch>
Date:   Wed, 17 Jun 2026 11:17:37 +0200

[new] Demo: working one time withdrawal

Diffstat:
Msrc/lib/bank_api_post_accounts_withdrawals_confirm.h | 10+++++-----
Msrc/taler-digitizer.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 5 deletions(-)

diff --git a/src/lib/bank_api_post_accounts_withdrawals_confirm.h b/src/lib/bank_api_post_accounts_withdrawals_confirm.h @@ -118,11 +118,11 @@ struct TALER_BANK_PostWithdrawalConfirmHandle; * @return NULL on failure */ struct TALER_BANK_PostWithdrawalConfirmHandle * -TALER_BANK_post_accounts_withdrawal_confirm_confirm_create ( struct GNUNET_CURL_Context *ctx, - const char *base_url, - const char *username, - const struct DIGITIZER_BankAuthenticationData *authorization); - +TALER_BANK_post_withdrawal_confirm_create ( struct GNUNET_CURL_Context *ctx, + const char *base_url, + const char *username, + const char *wopid, + const struct DIGITIZER_BankAuthenticationData *authorization); /** * Http request POST /accounts/withdrawal/confirm diff --git a/src/taler-digitizer.c b/src/taler-digitizer.c @@ -55,6 +55,9 @@ #define ACCEPT_CASH_TIMEOUT_SECONDS 60 +#define CASHUP_TIMEOUT_SECONDS 60 +#define CASHUP_CHECK_BALANCE_INTERVAL_MILISECONDS 200 + #define DISPLAY_BLOCK_SIZE 1024 #define DISPLAY_COUNT 750 @@ -202,6 +205,11 @@ static struct TALER_BANK_GetWithdrawalHandle *get_withdrawal_handle; static struct TALER_BANK_PostCreateWithdrawalHandle *post_accounts_withdrawal_handle; /** + * Handle for post_accounts_withdrawal_confirm request + */ +static struct TALER_BANK_PostWithdrawalConfirmHandle *post_withdrawal_confirm_handle; + +/** * used to init gpio */ static struct gpiod_line_settings *gpio_settings; @@ -502,6 +510,24 @@ on_get_accounts_done(void *cls, return; } + +/** + * Timeout when Money is not sent in + * CASHUP_TIMEOUT_SECONDS + */ +static void +timeout_CashingUp_task(void *cls) +{ + TALER_LOG_DEBUG ("Timeout of Cashing Up\n"); + + (void) cls; + + state = DIGITIZER_STATE_TERMINAL_ERROR; + GNUNET_SCHEDULER_add_now(state_controller_task,NULL); + return; +} + + /** * callback of accounts withdrawal request * used in the QR Create state @@ -525,6 +551,37 @@ on_post_accounts_withdrawal_done(void *cls, /** + * callback of accounts withdrawal request + * used in the QR Create state + */ +static void +on_post_withdrawal_confirm_done(void *cls, + const struct TALER_BANK_WithdrawalConfirmResponse *vr) +{ + TALER_LOG_DEBUG ("Callback of accounts/$USERNAME/withdrawal/$WOPID/confirm\n"); + (void) cls; + (void) vr; + //struct GNUNET_SCHEDULER_Task *timeout_handle; + struct GNUNET_TIME_Relative delay; + //struct GNUNET_TIME_Relative poll; + + post_withdrawal_confirm_handle = NULL; + delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, + CASHUP_TIMEOUT_SECONDS); + //get reserve + //poll = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, + // CASHUP_CHECK_BALANCE_INTERVAL_MILISECONDS); + //timeout_handle = + GNUNET_SCHEDULER_add_delayed(delay, + timeout_CashingUp_task, + NULL); + state = DIGITIZER_STATE_TERMINAL_ERROR; + GNUNET_SCHEDULER_add_now(state_controller_task,NULL); + return; +} + + +/** * When UART signal from Coin Acceptor * recived, or timeout of ACCEPT_CASH_TIMEOUT_SECONDS */ @@ -642,6 +699,7 @@ get_withdrawal_task(void *cls) return; } + /** * Timeout when QR is shown * SCAN_QR_TIMEOUT_SECONDS without been scanned @@ -659,6 +717,7 @@ timeout_ScanQR_task(void *cls) return; } + /** * @brief Cleanup when no task is scheduled anymore * @@ -687,6 +746,11 @@ shutdown_task (void *cls) TALER_BANK_post_withdrawal_create_cancel(post_accounts_withdrawal_handle); post_accounts_withdrawal_handle = NULL; } + if (NULL != post_withdrawal_confirm_handle) + { + TALER_BANK_post_withdrawal_confirm_cancel(post_withdrawal_confirm_handle); + post_withdrawal_confirm_handle = NULL; + } if (NULL != reschedule_ctx) { GNUNET_CURL_gnunet_rc_destroy (reschedule_ctx); @@ -1289,6 +1353,7 @@ static void CountMoney_state_task(void *cls) } } + static void AcceptCash_state_task(void *cls) { TALER_LOG_DEBUG("AcceptingCash state"); @@ -1299,6 +1364,41 @@ static void AcceptCash_state_task(void *cls) GNUNET_SCHEDULER_add_read_net(delay,filestream_ca,on_coin_recived,NULL); } + +static void CashingUP_state_task(void *cls) +{ + TALER_LOG_DEBUG("CashingUP state"); + (void)cls; + struct TALER_BANK_AccountWithdrawalConfirmRequest *wcr; + wcr = GNUNET_new(struct TALER_BANK_AccountWithdrawalConfirmRequest); + wcr->amount = state_ctx->digitizer_user_balance; + char* balance_str; + balance_str = TALER_amount_to_string(&state_ctx->digitizer_user_balance); + TALER_LOG_DEBUG ("CashingUP: %s\n",balance_str); + gpiod_line_request_set_value(rl_ca_inhibit, + (unsigned int)cfg_ca_inhibit_pin, + GPIOD_LINE_VALUE_INACTIVE); + post_withdrawal_confirm_handle = + TALER_BANK_post_withdrawal_confirm_create (curl_ctx, + cfg_bank_base_url, + cfg_bank_account_username, + state_ctx->wi.withdrawal_id, + cfg_bank_authentication); + if(GNUNET_OK != + TALER_BANK_post_withdrawal_confirm(post_withdrawal_confirm_handle, + wcr, + on_post_withdrawal_confirm_done, + NULL)) + { + TALER_LOG_ERROR("TALER_BANK_post_withdrawal_confirm canceled\n"); + state = DIGITIZER_STATE_TERMINAL_ERROR; + GNUNET_SCHEDULER_add_now(state_controller_task,NULL); + GNUNET_free(wcr); + } + GNUNET_free(wcr); +} + + /** * Switch between State tasks */ @@ -1343,6 +1443,11 @@ static void state_controller_task(void *cls) GNUNET_SCHEDULER_add_now(AcceptCash_state_task,NULL); return; } + case DIGITIZER_STATE_CASHING_UP: + { + GNUNET_SCHEDULER_add_now(CashingUP_state_task,NULL); + return; + } default: {