summaryrefslogtreecommitdiff
path: root/c2ec/wire-gateway.go
diff options
context:
space:
mode:
Diffstat (limited to 'c2ec/wire-gateway.go')
-rw-r--r--c2ec/wire-gateway.go76
1 files changed, 60 insertions, 16 deletions
diff --git a/c2ec/wire-gateway.go b/c2ec/wire-gateway.go
index 424c69c..0e793af 100644
--- a/c2ec/wire-gateway.go
+++ b/c2ec/wire-gateway.go
@@ -2,6 +2,7 @@ package main
import (
"context"
+ "errors"
"log"
http "net/http"
"strconv"
@@ -73,6 +74,24 @@ type OutgoingBankTransaction struct {
}
func NewIncomingReserveTransaction(w *Withdrawal) *IncomingReserveTransaction {
+
+ if w == nil {
+ LogWarn("wire-gateway", "the withdrawal was nil")
+ return nil
+ }
+
+ provider, err := DB.GetProviderByTerminal(int(*w.TerminalId))
+ if err != nil {
+ LogError("wire-gateway", err)
+ return nil
+ }
+
+ client := PROVIDER_CLIENTS[provider.Name]
+ if client == nil {
+ LogError("wire-gateway", errors.New("no provider client with name="+provider.Name))
+ return nil
+ }
+
t := new(IncomingReserveTransaction)
t.Amount = Amount{
Value: uint64(w.Amount.Val),
@@ -82,8 +101,8 @@ func NewIncomingReserveTransaction(w *Withdrawal) *IncomingReserveTransaction {
t.Date = Timestamp{
Ts: int(w.RegistrationTs),
}
- t.DebitAccount = "" // TODO provider specific payto uri -> needs new interface operation
- t.ReservePub = EddsaPublicKey(w.ReservePubKey)
+ t.DebitAccount = client.FormatPayto(w)
+ t.ReservePub = FormatEddsaPubKey(w.ReservePubKey)
t.RowId = int(w.WithdrawalId)
t.Type = INCOMING_RESERVE_TRANSACTION_TYPE
return t
@@ -97,7 +116,7 @@ func NewOutgoingBankTransaction(tr *Transfer) *OutgoingBankTransaction {
Currency: tr.Amount.Curr,
}
t.Date = Timestamp{
- Ts: int(tr.TransactionTs),
+ Ts: int(tr.TransferTs),
}
t.CreditAccount = tr.CreditAccount
t.ExchangeBaseUrl = tr.ExchangeBaseUrl
@@ -170,7 +189,21 @@ func transfer(res http.ResponseWriter, req *http.Request) {
return
}
- t, err := DB.GetTransferById(transfer.RequestUid)
+ decodedRequestUid, err := talerBase32Decode(string(transfer.RequestUid))
+ if err != nil {
+ err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
+ TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_TRANSFER_INVALID_REQ",
+ Title: "invalid request",
+ Detail: "the transfer request is malformed (error: " + err.Error() + ")",
+ Instance: req.RequestURI,
+ })
+ if err != nil {
+ res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR)
+ }
+ return
+ }
+
+ t, err := DB.GetTransferById(decodedRequestUid)
if err != nil {
err := WriteProblem(res, HTTP_INTERNAL_SERVER_ERROR, &RFC9457Problem{
TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_DATABASE_FAILURE",
@@ -187,7 +220,7 @@ func transfer(res http.ResponseWriter, req *http.Request) {
if t == nil {
// no transfer for this request_id -> generate new
err := DB.AddTransfer(
- transfer.RequestUid,
+ decodedRequestUid,
&transfer.Amount,
transfer.ExchangeBaseUrl,
string(transfer.Wtid),
@@ -315,6 +348,10 @@ func historyIncoming(res http.ResponseWriter, req *http.Request) {
}
}
+ if delta == 0 {
+ delta = 10
+ }
+
if shouldStartLongPoll {
// wait for the completion of the context
@@ -331,7 +368,7 @@ func historyIncoming(res http.ResponseWriter, req *http.Request) {
err := WriteProblem(res, HTTP_INTERNAL_SERVER_ERROR, &RFC9457Problem{
TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_DATABASE_FAILURE",
Title: "database request failed",
- Detail: "there was an error processing the database query",
+ Detail: "there was an error processing the database query. error=" + err.Error(),
Instance: req.RequestURI,
})
if err != nil {
@@ -345,9 +382,12 @@ func historyIncoming(res http.ResponseWriter, req *http.Request) {
return
}
- transactions := make([]*IncomingReserveTransaction, len(withdrawals))
+ transactions := make([]*IncomingReserveTransaction, 0)
for _, w := range withdrawals {
- transactions = append(transactions, NewIncomingReserveTransaction(w))
+ transaction := NewIncomingReserveTransaction(w)
+ if transaction != nil {
+ transactions = append(transactions, transaction)
+ }
}
enc, err := NewJsonCodec[[]*IncomingReserveTransaction]().EncodeToBytes(&transactions)
@@ -412,12 +452,8 @@ func historyOutgoing(res http.ResponseWriter, req *http.Request) {
if shouldStartLongPoll {
- // wait for the completion of the context
- waitMs, cancelFunc := context.WithTimeout(req.Context(), time.Duration(longPollMilli)*time.Millisecond)
- defer cancelFunc()
-
// this will just wait / block until the milliseconds are exceeded.
- <-waitMs.Done()
+ time.Sleep(time.Duration(longPollMilli) * time.Millisecond)
}
transfers, err := DB.GetTransfers(start, delta)
@@ -435,13 +471,21 @@ func historyOutgoing(res http.ResponseWriter, req *http.Request) {
return
}
- if len(transfers) < 1 {
+ filtered := make([]*Transfer, 0)
+ for _, t := range transfers {
+ if t.Status == 0 {
+ // only consider transfer which were successful
+ filtered = append(filtered, t)
+ }
+ }
+
+ if len(filtered) < 1 {
res.WriteHeader(HTTP_NOT_FOUND)
return
}
- transactions := make([]*OutgoingBankTransaction, len(transfers))
- for _, t := range transfers {
+ transactions := make([]*OutgoingBankTransaction, len(filtered))
+ for _, t := range filtered {
transactions = append(transactions, NewOutgoingBankTransaction(t))
}