cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

commit ec79baf90c10dc418486ad4df5d5f164b6195c52
parent f427a43ab0ed83535ffac06dc6fed189c99dd808
Author: Joel-Haeberli <haebu@rubigen.ch>
Date:   Sat, 18 May 2024 15:38:13 +0200

fix: wire gateway amount format

Diffstat:
Mc2ec/amount.go | 9+++++++++
Mc2ec/api-wire-gateway.go | 22++++++++++++++++------
2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/c2ec/amount.go b/c2ec/amount.go @@ -56,6 +56,15 @@ func ToAmount(amount *TalerAmountCurrency) (*Amount, error) { return a, nil } +func FormatAmount(amount *Amount) string { + + if amount == nil { + return "" + } + + return fmt.Sprintf("%s:%d.%d", amount.Currency, amount.Value, amount.Fraction) +} + // The maximim length of a fraction (in digits) const FractionalLength = 8 diff --git a/c2ec/api-wire-gateway.go b/c2ec/api-wire-gateway.go @@ -30,7 +30,7 @@ type WireConfig struct { // https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferRequest type TransferRequest struct { RequestUid HashCode `json:"request_uid"` - Amount Amount `json:"amount"` + Amount string `json:"amount"` ExchangeBaseUrl string `json:"exchange_base_url"` Wtid ShortHashCode `json:"wtid"` CreditAccount string `json:"credit_account"` @@ -184,9 +184,15 @@ func transfer(res http.ResponseWriter, req *http.Request) { if t == nil { // no transfer for this request_id -> generate new - err := DB.AddTransfer( + a, err := ParseAmount(transfer.Amount) + if err != nil { + LogError("wire-gateway-api", err) + res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR) + return + } + err = DB.AddTransfer( decodedRequestUid, - &transfer.Amount, + a, transfer.ExchangeBaseUrl, string(transfer.Wtid), transfer.CreditAccount, @@ -198,9 +204,13 @@ func transfer(res http.ResponseWriter, req *http.Request) { } } else { // the transfer is only processed if the body matches. - if transfer.Amount.Value != uint64(t.Amount.Val) || - transfer.Amount.Fraction != uint64(t.Amount.Frac) || - transfer.Amount.Currency != t.Amount.Curr || + ta, err := ToAmount(t.Amount) + if err != nil { + LogError("wire-gateway-api", err) + res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR) + return + } + if transfer.Amount != FormatAmount(ta) || transfer.ExchangeBaseUrl != t.ExchangeBaseUrl || transfer.Wtid != ShortHashCode(t.Wtid) || transfer.CreditAccount != t.CreditAccount {