commit 6c4db15ef9c1592d1785ec8270a138aada9a5429
parent 0d9423bf84db892877c89a8ade6adaedf0ceb305
Author: Tellenbach Reto <tellr1@bfh.ch>
Date: Fri, 5 Jun 2026 19:12:42 +0200
[dbg] Tapler-api: get_account balance parsing corrections
Diffstat:
4 files changed, 65 insertions(+), 12 deletions(-)
diff --git a/src/lib/bank_api_get_accounts.c b/src/lib/bank_api_get_accounts.c
@@ -68,11 +68,6 @@ struct TALER_BANK_GetAccountsHandle
struct GNUNET_CURL_Job *job;
/**
- * Headers sent with http request
- */
- struct curl_slist *request_headers;
-
- /**
* The whole request line
*/
char *job_url;
@@ -93,12 +88,18 @@ decode_config_json (const json_t *resp_obj,
{
const json_t *channels_pack;
json_t *cnt;
+ json_t *blc;
bool contact_missing;
bool tan_channels_missing;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received body\n`%s'\n",
+ json_dumps(resp_obj, 0));
+
+
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("balance",
- &vi->balance),
+ GNUNET_JSON_spec_json ("balance",
+ &blc),
TALER_JSON_spec_amount_any ("debit_threshold",
&vi->debit_threshold),
GNUNET_JSON_spec_mark_optional (
@@ -133,6 +134,20 @@ decode_config_json (const json_t *resp_obj,
GNUNET_break_op (0);
return TALER_EC_GENERIC_JSON_INVALID;
}
+ struct GNUNET_JSON_Specification spec_blc[] = {
+ TALER_JSON_spec_amount_any("amount",
+ &vi->balance.amount),
+ GNUNET_JSON_spec_string("credit_debit_indicator",
+ &vi->balance.credit_debit_indicator),
+ GNUNET_JSON_spec_end ()
+ };
+ if (GNUNET_OK != GNUNET_JSON_parse (blc,
+ spec_blc,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return TALER_EC_GENERIC_JSON_INVALID;
+ }
if(!contact_missing)
{
struct GNUNET_JSON_Specification spec_contact[] = {
diff --git a/src/lib/bank_api_get_accounts.h b/src/lib/bank_api_get_accounts.h
@@ -36,7 +36,7 @@ struct TALER_BANK_AccountInformation
/**
* Available balance on the account.
*/
- struct TALER_Amount balance;
+ struct TALER_BANK_Balance balance;
/**
* Number indicating the max debit allowed
diff --git a/src/taler-digitizer.c b/src/taler-digitizer.c
@@ -330,7 +330,7 @@ on_get_config_done (void *cls,
return;
}
state_ctx->bank_max_wire_transfer_amount = vr->details.ok.configi.max_wire_transfer_amount;
- if(-1 == TALER_amount_cmp(&(vr->details.ok.configi.min_wire_transfer_amount),
+ if(1 == TALER_amount_cmp(&(vr->details.ok.configi.min_wire_transfer_amount),
&(state_ctx->min_insertion_amount)))
{
GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
@@ -356,10 +356,38 @@ on_get_accounts_done(void *cls,
TALER_LOG_DEBUG ("Callback of accounts/$USERNAME\n");
(void) cls;
- (void) vr;
get_accounts_handle = NULL;
+ struct TALER_Amount account_max_withdrawal;
- ///LOGIC HERE
+ if(GNUNET_OK != strcmp("active",
+ vr->details.ok.acc.status))
+ {
+ GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
+ "taler-digitizer",
+ "BANK_ACCOUNT",
+ "bank account is not in active state");
+ state = DIGITIZER_STATE_TERMINAL_ERROR;
+ GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
+ return;
+ }
+ account_max_withdrawal =
+ ((-1 == TALER_amount_cmp(&vr->details.ok.acc.balance.amount,
+ &vr->details.ok.acc.debit_threshold))?
+ vr->details.ok.acc.balance.amount : vr->details.ok.acc.debit_threshold);
+ if(-1 == TALER_amount_cmp (&account_max_withdrawal,
+ &state_ctx->max_insertion_amount))
+ {
+ TALER_LOG_ERROR("bank account does not have enough balance or whithdrawal limit to withdrawal the biggest denomination");
+ state = DIGITIZER_STATE_TERMINAL_ERROR;
+ GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
+ return;
+ }
+ state_ctx->withdrawal_balance =
+ ((-1 == TALER_amount_cmp(&account_max_withdrawal,
+ &state_ctx->bank_max_wire_transfer_amount))?
+ account_max_withdrawal : state_ctx->bank_max_wire_transfer_amount);
+
+
state = DIGITIZER_STATE_SCAN_QR;
GNUNET_SCHEDULER_add_now(state_controller_task,NULL);
@@ -797,7 +825,7 @@ static void Init_state_task(void *cls)
static void TerminalError_state_task(void *cls)
{
(void)cls;
- TALER_LOG_DEBUG ("start TerminalErroe state task\n");
+ TALER_LOG_DEBUG ("start TerminalError state task\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown();
}
diff --git a/src/taler/taler_digitizer_service.h b/src/taler/taler_digitizer_service.h
@@ -152,6 +152,16 @@ struct TALER_BANK_ChallengeContactData
};
/**
+ * Balance data
+ */
+struct TALER_BANK_Balance
+{
+ struct TALER_Amount amount;
+
+ const char *credit_debit_indicator;
+};
+
+/**
* authentication data for requests to bank
*/
struct DIGITIZER_BankAuthenticationData